Re: [mongodb-user] find

16 views
Skip to first unread message

Nat

unread,
Jul 26, 2012, 1:59:12 AM7/26/12
to mongod...@googlegroups.com
You should store it as number instead of string and then you can use

{ "created" : { "$gt" : 1343010999 } }
From: R_J <jon...@gmail.com>
Date: Wed, 25 Jul 2012 22:01:04 -0700 (PDT)
Subject: [mongodb-user] find

data into colection contains
... ,
{"created":{"user1":"1343128189", "user2":"1343010109",...,"userN":"unix_timestamp"},
...

How to find all records where  at least one unix_timstamp great  1343010999?

--
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

R_J

unread,
Jul 26, 2012, 2:13:13 AM7/26/12
to mongod...@googlegroups.com, nat....@gmail.com
it's no worked (

Nat

unread,
Jul 26, 2012, 2:48:54 AM7/26/12
to mongod...@googlegroups.com, nat....@gmail.com
I'm sorry. It's my bad.... you cannot do that without using javascript or changing the way to store the data. If you modify the data format slightly, you will be able to do it:
 
> db.xx10.save({"created":[{"username":"user1", "timestamp":1343128189}, {"username":"user2","timestamp":1343010109}] })
> db.xx10.find({"created.timestamp" : {"$gt":1343128188}})
{ "_id" : ObjectId("5010e7e79b7b000000007e19"), "created" : [
        {
                "username" : "user1",
                "timestamp" : 1343128189
        },
        {
                "username" : "user2",
                "timestamp" : 1343010109
        }
] }
> db.xx10.find({"created.timestamp" : {"$gt":1343128189}})
> db.xx10.find({"created.timestamp" : {"$gt":1343100000}})
{ "_id" : ObjectId("5010e7e79b7b000000007e19"), "created" : [
        {
                "username" : "user1",
                "timestamp" : 1343128189
        },
        {
                "username" : "user2",
                "timestamp" : 1343010109
        }
] }
>

R_J

unread,
Jul 26, 2012, 3:04:29 AM7/26/12
to mongod...@googlegroups.com, nat....@gmail.com
Thanks, Nat

четверг, 26 июля 2012 г., 12:48:54 UTC+6 пользователь Nat написал:
Reply all
Reply to author
Forward
0 new messages