U kunt dit vrij eenvoudig doen op de documentpagina Mongo Extended JSON
(wat vrij goed verborgen is) kun je een tabel vinden die beschrijft hoe mongo extended datatypes in JSON kunnen worden weergegeven. Zoals u waarschijnlijk weet, zijn de eerste 4 bytes van ObjectId
de tijdstempel vertegenwoordigen, wordt deze rechtstreeks toegewezen aan 8 eerste tekens in de hexadecimale tekenreeks. Het volgende zou dus moeten werken:
[email protected]:~$ mongoexport -d so_test -c example -q '{"_id" : {"$gt" : {"$oid" : "4fad36290000000000000000"}}}'
connected to: 127.0.0.1
{ "_id" : { "$oid" : "4fad3629a8bbba98829d5c1e" }, "a" : "bar", "b" : 2 }
{ "_id" : { "$oid" : "4fad362ea8bbba98829d5c1f" }, "a" : "baz", "b" : 3 }
{ "_id" : { "$oid" : "4fad3635a8bbba98829d5c20" }, "a" : "buzz", "b" : 4 }
{ "_id" : { "$oid" : "4fad363ca8bbba98829d5c21" }, "a" : "fizz", "b" : 5 }
exported 4 records
[email protected]:~$
Hieronder staan alle commando's die voor het voorbeeld zijn gebruikt ter referentie.
> use so_test
switched to db so_test
> db.example.insert({a: "foo", b: 1})
> db.example.insert({a: "bar", b: 2})
> db.example.insert({a: "baz", b: 3})
> db.example.insert({a: "buzz", b: 4})
> db.example.insert({a: "fizz", b: 5})
> db.example.find()
{ "_id" : ObjectId("4fad3620a8bbba98829d5c1d"), "a" : "foo", "b" : 1 }
{ "_id" : ObjectId("4fad3629a8bbba98829d5c1e"), "a" : "bar", "b" : 2 }
{ "_id" : ObjectId("4fad362ea8bbba98829d5c1f"), "a" : "baz", "b" : 3 }
{ "_id" : ObjectId("4fad3635a8bbba98829d5c20"), "a" : "buzz", "b" : 4 }
{ "_id" : ObjectId("4fad363ca8bbba98829d5c21"), "a" : "fizz", "b" : 5 }
> db.example.find({_id : {$gt : ObjectId("4fad362e0000000000000000")}})
{ "_id" : ObjectId("4fad362ea8bbba98829d5c1f"), "a" : "baz", "b" : 3 }
{ "_id" : ObjectId("4fad3635a8bbba98829d5c20"), "a" : "buzz", "b" : 4 }
{ "_id" : ObjectId("4fad363ca8bbba98829d5c21"), "a" : "fizz", "b" : 5 }
>
bye
[email protected]:~$ mongodump -d so_test -c example -q '{"_id" : {"$gt" : {"$oid" : "4fad36290000000000000000"}}}'
connected to: 127.0.0.1
DATABASE: so_test to dump/so_test
so_test.example to dump/so_test/example.bson
4 objects
[email protected]:~$ mongoexport -d so_test -c example -q '{"_id" : {"$gt" : {"$oid" : "4fad36290000000000000000"}}}'
connected to: 127.0.0.1
{ "_id" : { "$oid" : "4fad3629a8bbba98829d5c1e" }, "a" : "bar", "b" : 2 }
{ "_id" : { "$oid" : "4fad362ea8bbba98829d5c1f" }, "a" : "baz", "b" : 3 }
{ "_id" : { "$oid" : "4fad3635a8bbba98829d5c20" }, "a" : "buzz", "b" : 4 }
{ "_id" : { "$oid" : "4fad363ca8bbba98829d5c21" }, "a" : "fizz", "b" : 5 }
exported 4 records