tags:

views:

17

answers:

1

For example, I can have documents like:

doc1 = {
  title: "First blog post",
  tags: ["family", "sensitive", "private"]
}

doc2 = {
  title: "Second blog post",
  tags: ["travel", "photos"]
}

And I would like to list all posts that don't contain the "private" tag (in the se above, that would return only doc2). I've tried doing this:

I've tried doing this:

db.posts.find({$not: {tags: 'private'}})

It returns nothing. I've tried this:

db.posts.find({$not: {tags: {$all: ['private']}}})

Nothing still.

Then I tried this:

db.posts.find({$where: function() { var i; for(i=0; i < this.tags.length; i++) {if (this.tags[i] == 'private'){ return false;}}; return true;}})

And that got me this error:

"$err" : "error on invocation of $where function:\nJS Error: TypeError: this.tags has no properties nofile_b:2",
        "code" : 10071

Any ideas?

+2  A: 

$not is a bit funky, use $ne:

db.posts.find({tags : {$ne : 'private'}})
kristina