Mongoskin object ID findAndModify ID

Using nodejs, mongoskin .. I would like to return an updated document so Im using findAndModify, however the query {_id: "someid"} does not work. I think I need to use {id: ObjectID {'someid'} as a request. How to get ObjectId type in JS?

+4
source share
3 answers

try the following:

ObjectID = require('mongoskin').ObjectID {_id: new ObjectID("someid")} 
+13
source

Here is the solution

 var mongo = require("mongoskin"); var conn = mongo.db(YOUR_DETAILS); var BSON = mongo.BSONPure; 

this allows you to convert your int, string id or something else:

 conn.collection(YOUR_COLLECTION).find({_id:new BSON.ObjectID(YOUR_ID)}) 

Hope this helps!

+2
source

You can do something like:

 yourCollection = db.collections('yourCollection'); 

Then

 { _id: yourCollection.id("someId") } 
+1
source

Source: https://habr.com/ru/post/1435085/


All Articles