Question

I have a collection of mongoDB entries like the one below...

{
  "_id": ObjectId("4e2a4ca7f21a81331f0006c3"),
  "users": {
    "bob": 1375496448, "alice": 1375496448
  },
  ...other values...
}

I am looking for a simple query for me to find all entries...
1) Without user x in users
2) With user x in users where the corresponding value is < y

I hope this question is not too trivial, but I just started learning mongoDB this afternoon and I would like to get it up and running in a simple server I am planning to set up. Thanks!

Was it helpful?

Solution

Assuming your collection is named users.

1)db.users.find({'users.X':{$exists:false}})

2)db.users.find({'users.X':{$lt:y}})

OTHER TIPS

Ishaan's answer should work for you. I am only adding a way to Union the two queries.

db.users.find( {$or: [ {'users.X':{$exists:false}}, {'users.X':{$lt:y}} ] } )

You will find documentation of operators like $or, $and, etc. on this page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top