A
A
Alex Kheben2014-03-14 13:53:16
MongoDB
Alex Kheben, 2014-03-14 13:53:16

How to fetch by object method in Mongodb?

I’ll make a reservation right away that I just started studying Mongodb and a number of questions arose about the capabilities of the database.
I can not solve the problem, I would like to know the opinions of experts, is it really possible to solve it at all or not.
db.collection.find({_id: ObjectId('str_id')})
I would like something more elegant, like:
db.collection.find({'_id.str': 'str_id'})
or
db.collection.find({'_id.valueOf()': 'str_id'})
If you really solve the last task, then you could make selections by time without having to store data about the date the record was created in a separate field, for example:

db.collection.find({'_id.getTimestamp().getMonth()': 2}) // выбор по месяцу

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-03-14
@pythonchik

it's easier to immediately write a month (year, day, or whatever) when adding records. Or then pull out a new collection of mapReduce.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question