This is the code snippet
send = mongo.db.subscription
send.find().update({'$set':{'status': "expired"}})
this is the output i get
send.find().update({'$set':{'status': "expired"}})
AttributeError: 'Cursor' object has no attribute 'update'
The syntax you want is:
send.update_many({<filter_condition>}, {'$set':{'status': "expired"}})
Related
I'm trying to order a firestore collection by the field name, but it's giving me this error: AttributeError: 'CollectionReference' object has no attribute 'orderBy'.
My code:
participants_ref = db.collection("participants")
docs = participants_ref.orderBy("name").stream()
In case this helps, I've also printed out participants_ref and I get the following:
<google.cloud.firestore_v1.collection.CollectionReference object at 0x0000021C9EAB7F40>
According to the documentation, the method you're looking for is order_by. Be sure to switch the code language tab to "Python" to see the correct usage.
docs = participants_ref.order_by("name").stream()
Also see the python API documentation for CollectionReference.
I have started using pymodm in my project (https://github.com/ypriverol/biocontainers-backend/blob/master/biocontainers/common/models.py). All CRUD operations work very well.
However, when I try to retrieve the list of objects for a specific MongoModel using the objects call:
tool_versions_dic = MongoToolVersion.objects.all()
I got this error:
AttributeError: type object 'MongoToolVersion' has no attribute 'objects'
So I have the following
b = Brand.objects.create(**model_fields_and_values)
b.save()
and then I try to associate that entry with
b._meta.get_field("myfield").add(value3)
and I get the error 'ManyToManyField' object has no attribute 'add'
How can I create an association using a string and not the field ???
I dont want to use b.myfield.add(value3)
getattr allows you to get an attribute using the attribute name:
getattr(b, 'myfield').add(value3)
q = Institution_Table.all().run(batch_size=2000).order('name')
gives me the following error:
AttributeError: '_QueryIterator' object has no attribute 'order'
The example given in the docs shows that .order('name') is attached to a query.
In your example you are attaching it after the query has been run.
Try:
q = Institution_Table.all().order('name')
results = q.run()
Here: https://developers.google.com/appengine/docs/python/datastore/queries#Restrictions_on_Queries
I am trying to make Django view that will give JSON responce with earliest and latest objects. But unfotunately it fails to work with this error.
'str' object has no attribute '_meta'
I have other serialization and it works.
Here is the code.
def get_calendar_limits(request):
result = serializers.serialize("json", Session.objects.aggregate(Max('date'), Min('date')), ensure_ascii=False)
return HttpResponse(result, mimetype="application/javascript")
Thanks a lot beforehand.
I get the same error when trying to serialize an object that is not derived from Django's Model
Python has "json" module. It can 'dumps' and 'loads' function. They can serialize and deserialize accordingly.
Take a look at the following:
objects= Session.objects.aggregate(Max('date'), Min('date'))
print [ type[o] for o in objects ]
result = serializers.serialize("json", objects, ensure_ascii=False)
You might want to just run the above in interactive Python as an experiment.
What type are your objects? Is that type serializable?