Can't use $and with Date.

1,510 views
Skip to first unread message

Charlie

unread,
Aug 1, 2012, 8:33:52 PM8/1/12
to mongod...@googlegroups.com
I have a simple $and query like this:

{
  "start": {
    $and: [
      { $gte: date1 },
      { $lte: date2 }
    ]
  }
}

I'm getting the error "Can't use $and with Date.".  This seems like an odd limitation.  Are there any fixes or efficient workarounds to this?

I suppose I could store the dates as numbers in the database but I'd rather keep them as Date objects if possible.

Thanks

Nat

unread,
Aug 1, 2012, 9:02:00 PM8/1/12
to mongod...@googlegroups.com
Shouldn't this work without $and?

{
  "start": {
    $gte: date1,
     $lte: date2
  }
}

From: Charlie <cha...@powmedia.co.uk>
Date: Wed, 1 Aug 2012 17:33:52 -0700 (PDT)
Subject: [mongodb-user] Can't use $and with Date.
--
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

Charles Davison

unread,
Aug 1, 2012, 9:18:13 PM8/1/12
to mongod...@googlegroups.com
D'oh!  Don't know why I thought I had to use an $and for this.. time to get some sleep!

Thanks for the quick help!
Reply all
Reply to author
Forward
0 new messages