Finding MongoDB Document by ID

Alex H Hadik

I'm using Node.js and MongoDB with my database hosted on MongoHQ (Now compose.io). I have a general understanding document IDs are converted to hex strings but I can't figure out how to retrieve a document using its ID.

My document has the ID _id: ObjectId("53f13064b5a39cc69f00011b") as in that's how it's displayed in Compose's interface. When I retrieve the document by brute force, the ID is shown as _id: 53f13064b5a39cc69f00011b.

What do I use in Node.js to retrieve this document? The query:

systemData.find({_id: "53f13064b5a39cc69f00011b"}).toArray(function(err, data) {//do stuff}

returns an empty set but so does querying with an object ID object

systemData.find({_id: new ObjectID("53f13064b5a39cc69f00011b")}).toArray(function(err, data) {//do stuff}

What am I missing?

vintastic

You should be able to use:

systemData.find({_id: ObjectID("53f13064b5a39cc69f00011b")})

No need for the "new" on the beginning.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding MongoDB Document by ID

From Dev

Finding subelements in a document in mongodb

From Dev

How to prevent MongoDB from returning the object ID when finding a document?

From Dev

How to prevent MongoDB from returning the object ID when finding a document?

From Dev

MongoDB finding using an _id

From Dev

Finding by id in MongoDB returns null

From Dev

Query the _id of a document in MongoDB

From Dev

Finding a MongoDB document by different types with Mongoskin

From Dev

Finding words from two properties in a mongodb document

From Dev

Finding words from two properties in a mongodb document

From Dev

Get MongoDB document by ID on Java

From Dev

Find mongodb document by _id nodejs mongodb native

From Dev

Find mongodb document by _id nodejs mongodb native

From Dev

Finding a MongoDB document through a word in a field description in each product with Mongoskin

From Dev

mongodb node.js finding document with multiple Ids present in an Array

From Dev

Finding document based on date range works in the mongodb shell, but not with pymongo

From Dev

Meteor.js / MongoDB : finding a document's place in a collection

From Dev

Mongo and Node.js: Finding a document by _id using a UUID (GUID)

From Dev

Mongodb php7, Update document by id?

From Dev

Update field inside document by id in MongoDB

From Dev

Embed document without knowing _id in Mongoose/Mongodb

From Dev

Find a mongodb document using a partial _id string

From Dev

find in mongodb document with custom poco object as id

From Dev

mongodb insert document with just id, or do nothing

From Dev

Laravel MongoDB Jenssegers How to get "_id" of a document

From Dev

Unable to get id filed from mongodb document

From Dev

Fetch _id of a Document in MongoDB 3.3.0 above

From Dev

How to count in embedded document of MongoDB for each _id

From Dev

How to define a complex MongoDb document Id?

Related Related

  1. 1

    Finding MongoDB Document by ID

  2. 2

    Finding subelements in a document in mongodb

  3. 3

    How to prevent MongoDB from returning the object ID when finding a document?

  4. 4

    How to prevent MongoDB from returning the object ID when finding a document?

  5. 5

    MongoDB finding using an _id

  6. 6

    Finding by id in MongoDB returns null

  7. 7

    Query the _id of a document in MongoDB

  8. 8

    Finding a MongoDB document by different types with Mongoskin

  9. 9

    Finding words from two properties in a mongodb document

  10. 10

    Finding words from two properties in a mongodb document

  11. 11

    Get MongoDB document by ID on Java

  12. 12

    Find mongodb document by _id nodejs mongodb native

  13. 13

    Find mongodb document by _id nodejs mongodb native

  14. 14

    Finding a MongoDB document through a word in a field description in each product with Mongoskin

  15. 15

    mongodb node.js finding document with multiple Ids present in an Array

  16. 16

    Finding document based on date range works in the mongodb shell, but not with pymongo

  17. 17

    Meteor.js / MongoDB : finding a document's place in a collection

  18. 18

    Mongo and Node.js: Finding a document by _id using a UUID (GUID)

  19. 19

    Mongodb php7, Update document by id?

  20. 20

    Update field inside document by id in MongoDB

  21. 21

    Embed document without knowing _id in Mongoose/Mongodb

  22. 22

    Find a mongodb document using a partial _id string

  23. 23

    find in mongodb document with custom poco object as id

  24. 24

    mongodb insert document with just id, or do nothing

  25. 25

    Laravel MongoDB Jenssegers How to get "_id" of a document

  26. 26

    Unable to get id filed from mongodb document

  27. 27

    Fetch _id of a Document in MongoDB 3.3.0 above

  28. 28

    How to count in embedded document of MongoDB for each _id

  29. 29

    How to define a complex MongoDb document Id?

HotTag

Archive