Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

mongodb - How do I do a "NOT IN" query in Mongo?

This is my document:

{ 
    title:"Happy thanksgiving",
    body: "come over for dinner",
    blocked:[
       {user:333, name:'john'},
       {user:994, name:'jessica'},
       {user:11, name: 'matt'},
    ]
}

What is the query to find all documents that do not have user 11 in "blocked"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use $in or $nin for "not in"

Example ...

> db.people.find({ crowd : { $nin: ["cool"] }});

I put a bunch more examples here: http://learnmongo.com/posts/being-part-of-the-in-crowd/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...