R
R
Rustem Vorozheikin2015-05-19 20:31:13
MongoDB
Rustem Vorozheikin, 2015-05-19 20:31:13

For what reasons can a query in mongodb like db.presets.find({}, {"name":1}) not work?

Good afternoon.
On my PC, I created a selection from the mongo base, which should select the names of all fields in the presets collection.
Everything works correctly on the PC, but when uploaded to 2 different servers, nothing works =(
Through trial / error / tests, I came to the conclusion that the line does not work:

presets_names1 = db.presets.find({}, {"name":1})
args['presets_names1'] = presets_names1

Since in the django template, this code does not output anything:
{% for pres1 in presets_names1 %}
<label class="radio">
<input class="pres1" type="radio" name="group1" value="{{ pres1.name }}">{{ pres1.name }}
</label>
{% endfor %}

The fact is that other requests from this collection work and are displayed in the template..
pres = presets_col.find_one({'name':preset})
preset_username = pres['login']

There may be a mistake in a small detail, but I have been unable to find it for more than 5 hours. So the question arose, maybe someone came across, for what reasons the query db.presets.find({}, {"name":1}) might not work?
Again, everything works on my PC. on the PC and two servers have the same bases. Versions of mongodb 3. Django: 1.8.1 on the PC and one server, and the second 1.7.7.
I will be grateful for any help. =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-05-19
@lega

db.presets.find - returns an iterator, i.e. the data can be "read" once, perhaps you "subtracted" it before the template. Try turning it into an array right away (for small lists):

presets_names1 = list(db.presets.find({}, {"name":1}))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question