1

this is the query:

mongoexport --host our.dbhost.com --port 27017 --username peter -p clark --collection sent_mails --db dbname --query '{trigger_id:ObjectId( "50c62e97b9fe6a000200000c"), updated_at: {$lt : ISODate("2013-02-28"), $gte : ISODate("2013-02-01") }}'

when I run this command I get:

assertion: 10340 Failure parsing JSON string near: , updated_

any ideas? (i want all records that match the trigger_id that were updated in February.)

1 Answer 1

1

as explained in this issue: Mongoexport using $gt and $lt constraints on a date range, you have to use Unix time stamps for date queries in mongoexport

The time stamps have to be in milliseconds

Invoking this in the bash shell would look like this:

let "date_from=`date --utc --date "2013-02-01" +%s` * 1000"
let "date_to=`date --utc --date "2013-03-01" +%s` * 1000"
mongoexport -d test -c xx --query "{updated_at:{\$gte:new Date($date_from),\$lt:new Date($date_to)}}"> xx.json
> connected to: 127.0.0.1
> exported 1 records

The xx colletion contains:

> db.xx.find().pretty()
{
    "_id" : ObjectId("5158f670c2293fc7aadd811e"),
    "trigger_id" : ObjectId("50c62e97b9fe6a000200000c"),
    "updated_at" : ISODate("2013-02-11T00:00:00Z")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.