$elemMatch projection

38 views
Skip to first unread message

J Y

unread,
Mar 21, 2013, 8:46:39 PM3/21/13
to cfmo...@googlegroups.com
Hi all,

Is this available in API?  I am trying to do an $elemMatch projection, and was not able to get it to work.

This is the mongodb query I am trying to perform:

db.test.find({}, {"change": {"$elemMatch": {"latest": 1}}});

I tried this in cfmongodb:

<cfset result = test.find(criteria={}, keys='{"change" : {"$elemMatch" : {"latest" : 1}}}').asArray() />

Where "latest" is a field in the "change" array.  The result returned does not actually contain the field I am looking for.

Thanks in advance for any help.

Marc Esher

unread,
Mar 27, 2013, 7:51:21 AM3/27/13
to cfmo...@googlegroups.com
Hey JY,

I thought elemMatch was to be used in the criteria document, i.e.

test.find(criteria={"change": {"$elemMatch": {"latest": 1}}})

The keys argument simply limits the fields which are returned.

Marc


--
You received this message because you are subscribed to the Google Groups "CFMongoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfmongodb+...@googlegroups.com.
To post to this group, send email to cfmo...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfmongodb?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

J Y

unread,
Mar 27, 2013, 4:46:35 PM3/27/13
to cfmo...@googlegroups.com
Hi Marc,

We are trying to limit the amount of data that gets returned from a document with a large array using a elemMatch.  The Java driver's find can accept a DBObject that has a elemMatch in it in the keys argument, just looking for a way to pass a struct of that into cfmongodb.

Thanks,

J

Marc Esher

unread,
Mar 27, 2013, 5:57:18 PM3/27/13
to cfmo...@googlegroups.com
So are you saying that using elemMatch in the mongo console works as a key, but doesn't work in your app code?

When you turn on profiling, what do you see as the actual query that Mongo is getting? That's often helpful in debugging.
Reply all
Reply to author
Forward
0 new messages