4

Using nodejs, mongoskin.. I'd like to return the updated doc so Im using findAndModify, however the query {_id: "someid"} doesn't work. I think I need to use {id: ObjectID{'someid'} as the query. How do I get the ObjectId type into JS?

C B
  • 12,482
  • 5
  • 36
  • 48

3 Answers3

13

try this:

ObjectID = require('mongoskin').ObjectID

{_id: new ObjectID("someid")}
Harry
  • 87,580
  • 25
  • 202
  • 214
label
  • 131
  • 1
  • 3
2

Here is a solution

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

this enables you to convert your id int, string or whatever using:

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

Hope that helps!

tim
  • 3,191
  • 2
  • 15
  • 17
1

You can do something like:

yourCollection = db.collections('yourCollection');

Then

{ _id: yourCollection.id("someId") }
andrewkshim
  • 206
  • 3
  • 3