Issue using $all

22 views
Skip to first unread message

Tim Rieder

unread,
May 15, 2012, 12:13:42 AM5/15/12
to MongoDb
I have an array of strings that I want to search (I'm interested in
finding this particular entry):

> db.FTS.findOne({"_id":ObjectId("4fb1c5bdd160d1c77dc594a3")})
{
"_id" : ObjectId("4fb1c5bdd160d1c77dc594a3"),
"data" : [
"first",
"comment",
"second",
"comment"
]
}

So I do a search and get a result:

> db.FTS.findOne({data:{$all:['first','second']}})
{
"_id" : ObjectId("4fb1c5bdd160d1c77dc594a3"),
"data" : [
"first",
"comment",
"second",
"comment"
]
}

Now I want to add the word comment:

> db.FTS.findOne({data:{$all:['first','second','comment']}})
null

Why is this null?

Thanks!

Andreas Jung

unread,
May 15, 2012, 12:21:13 AM5/15/12
to mongod...@googlegroups.com
MongoDB version?

Working as it should with 2.0.4

> db.foo.findOne({data:{$all:['first','second']}})
{
"_id" : ObjectId("4fb1d97efaecad328c6964d8"),
"data" : [
"first",
"comment",
"second",
"comment"
]
}
> db.foo.findOne({data:{$all:['first','second', 'comment']}})
{
"_id" : ObjectId("4fb1d97efaecad328c6964d8"),
"data" : [
"first",
"comment",
"second",
"comment"
]
}
>

-aj
--
ZOPYX Limited | Python | Zope | Plone | MongoDB
Charlottenstr. 37/1 | Consulting & Development
D-72070 T�bingen | Electronic Publishing Solutions
www.zopyx.com | Scalable Web Solutions
--------------------------------------------------
Produce & Publish - www.produce-and-publish.com


Tim Rieder

unread,
May 15, 2012, 12:23:31 AM5/15/12
to mongod...@googlegroups.com
> db.version()
2.0.5
> D-72070 Tübingen      | Electronic Publishing Solutions
> www.zopyx.com         | Scalable Web Solutions
> --------------------------------------------------
> Produce & Publish - www.produce-and-publish.com
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Kyle Banker

unread,
May 15, 2012, 10:37:49 AM5/15/12
to mongod...@googlegroups.com
I've just tested this in 2.0.5:

MongoDB shell version: 2.0.5
connecting to: test
> db.foo.find()
> db.foo.save({a: ['first', 'comment', 'second', 'comment']})
> db.foo.find({a: {$all: ['first']}})
{ "_id" : ObjectId("4fb269d90d558e435226a0ff"), "a" : [ "first", "comment", "second", "comment" ] }
> db.foo.find({a: {$all: ['first', 'second']}})
{ "_id" : ObjectId("4fb269d90d558e435226a0ff"), "a" : [ "first", "comment", "second", "comment" ] }
> db.foo.find({a: {$all: ['first', 'second', 'comment']}})
{ "_id" : ObjectId("4fb269d90d558e435226a0ff"), "a" : [ "first", "comment", "second", "comment" ] }

> db.foo.ensureIndex({a: 1})
> db.foo.find({a: {$all: ['first', 'second', 'comment']}})
{ "_id" : ObjectId("4fb269d90d558e435226a0ff"), "a" : [ "first", "comment", "second", "comment" ] }

Seems to work with and without an index. Are we missing something?

Tim Rieder

unread,
May 15, 2012, 11:46:46 PM5/15/12
to mongod...@googlegroups.com
Not sure if it makes a difference, but I am inserting these values via
the Mongo Java API (mongo-2.7.2.jar). I have an ObjectId and a
String[] that I'm inserting like so:

insert.append("_id", oid).append("data", scrubbed);
ftsCol.insert(insert.get());

To be clear:

oid is an ObjectId
insert is a BasicDBObjectBuilder
ftsCol is a DBCollection
scrubbed is String[]

Any other info necessary?
>> > mongodb-user...@googlegroups.com
>> > See also the IRC channel -- freenode.net#mongodb
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com

Mario

unread,
May 16, 2012, 1:31:32 AM5/16/12
to mongod...@googlegroups.com
Is it possible to use $regexp with $all to find document by substring of tags ?

    db.FTS.findOne({data:{$all:['firs','sec]}}) 
>> > See also the IRC channel -- freenode.net#mongodb
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to

Andreas Jung

unread,
May 16, 2012, 1:34:34 AM5/16/12
to mongod...@googlegroups.com
What has this to do with the original question?

-aj
> <and...@andreas-jung.com <mailto:and...@andreas-jung.com>>
> >> > D-72070 T�bingen | Electronic Publishing Solutions
> >> > www.zopyx.com <http://www.zopyx.com> | Scalable Web
> Solutions
> >> > --------------------------------------------------
> >> > Produce & Publish - www.produce-and-publish.com
> <http://www.produce-and-publish.com>
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "mongodb-user" group.
> >> > To post to this group, send email to
> mongod...@googlegroups.com <mailto:mongod...@googlegroups.com>
> >> > To unsubscribe from this group, send email to
> >> > mongodb-user...@googlegroups.com
> <mailto:mongodb-user%2Bunsu...@googlegroups.com>
> >> > See also the IRC channel -- freenode.net#mongodb
> <http://freenode.net#mongodb>
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com
> <mailto:mongod...@googlegroups.com>
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com
> <mailto:mongodb-user%2Bunsu...@googlegroups.com>
> > See also the IRC channel -- freenode.net#mongodb
> <http://freenode.net#mongodb>
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

--
ZOPYX Limited | Python | Zope | Plone | MongoDB
Charlottenstr. 37/1 | Consulting & Development
D-72070 T�bingen | Electronic Publishing Solutions

Mario

unread,
May 16, 2012, 2:03:34 AM5/16/12
to mongod...@googlegroups.com, and...@andreas-jung.com
Sorry for the post in the topic
>     <and...@andreas-jung.com <mailto:andreas@andreas-jung.com>>
>     >> > D-72070 T�bingen      | Electronic Publishing Solutions
>     >> > www.zopyx.com <http://www.zopyx.com>         | Scalable Web
>     Solutions
>     >> > --------------------------------------------------
>     >> > Produce & Publish - www.produce-and-publish.com
>     <http://www.produce-and-publish.com>
>     >> >
>     >> >
>     >> > --
>     >> > You received this message because you are subscribed to the Google
>     >> > Groups "mongodb-user" group.
>     >> > To post to this group, send email to
>     mongod...@googlegroups.com <mailto:mongodb-user@googlegroups.com>
>     >> > To unsubscribe from this group, send email to
>     >> > mongodb-user+unsubscribe@googlegroups.com
>     <mailto:mongodb-user%2Bunsu...@googlegroups.com>
>     >> > See also the IRC channel -- freenode.net#mongodb
>     <http://freenode.net#mongodb>
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "mongodb-user" group.
>     > To post to this group, send email to mongod...@googlegroups.com
>     <mailto:mongodb-user@googlegroups.com>
>     > To unsubscribe from this group, send email to
>     > mongodb-user+unsubscribe@googlegroups.com
>     <mailto:mongodb-user%2Bunsu...@googlegroups.com>
>     > See also the IRC channel -- freenode.net#mongodb
>     <http://freenode.net#mongodb>
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

--
ZOPYX Limited         | Python | Zope | Plone | MongoDB
Charlottenstr. 37/1   | Consulting & Development
D-72070 T�bingen      | Electronic Publishing Solutions

Timothy Rieder

unread,
May 16, 2012, 8:09:47 AM5/16/12
to mongod...@googlegroups.com
I dumped the db. I converted the bson to json and I found \u0000 in some of my strings. Not sure how they got there because I typed the strings by hand. Must be something in my loading code...

Kyle Banker

unread,
May 16, 2012, 9:16:23 AM5/16/12
to mongod...@googlegroups.com
If you were explicitly adding a null byte, that could have been the problem. Is it working now?
>>>> mongodb-user+unsubscribe@googlegroups.com
>>>> See also the IRC channel -- freenode.net#mongodb
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "mongodb-user" group.
>> To post to this group, send email to mongod...@googlegroups.com
>> To unsubscribe from this group, send email to
>> mongodb-user+unsubscribe@googlegroups.com
Reply all
Reply to author
Forward
0 new messages