Questions tagged [mongoengine]
MongoEngine is a Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python. It uses a simple declarative API, similar to the Django ORM.
1,830
questions
0
votes
0
answers
18
views
mongoengine error with fastapi "pymongo.errors.operationfailure: authentication failed."
The below code snipet is connecting with mongo client and working
client = MongoClient("mongodb://root:password@127.0.0.1:27017/fast_api")
db1 = client['fast_api']
@router.get(&...
1
vote
0
answers
29
views
In mongoengine how do you target a specific index in a list?
In mongoengine there are pull and unset commands. These allow you to remove values from a list if you provide them with a value to match against or the entire list. While that works without an issue ...
0
votes
2
answers
25
views
How to bulk transfer JSON via MongoEngine
Trying to send a lot of data to MongoDB through MongoEngine. I start with a DataFrame that I write to JSON like this:
result = df.to_json(orient="index")
parsed = json.loads(result)
...
0
votes
0
answers
19
views
ModuleNotFoundError: No module named 'mongoengine.django'
I have been having a problem installing the dependencies from the social library.
i have basically to install two dependencies, makemigrations, and migrate them normally.
According to the ...
0
votes
1
answer
34
views
Divide a MongoDB document into multiple documents based on Date Field using aggregation
I have a document on MongoDB that contains flight data records. This data goes back 4 years , and is mixed up in the flight_records array shown in the sample below. I want to split this document into ...
1
vote
0
answers
25
views
Decoding an image retrieved from mongodb to make it json serializable
I have some images saved in mongodb and I used mongoengine and flask to save them. Now I want to make it json serializable so I can send it to a react frontend. This is the code that I used to decode ...
0
votes
1
answer
19
views
Does MongoEngine have an "AutoField()" like Django?
I just switched from SQL to MongoDB. When I was changing all my model fields from Django fields to MongoEngine fields, I realized there was no AutoField(). Does anyone know a substitute for this?
0
votes
0
answers
44
views
mongoengine how to use a variable as a field?
How do you use a variable as a field to find a specific value within a mongodb database? I am trying to target a list inside of a list in my collection making use of an integer variable that is ...
0
votes
0
answers
27
views
How get _instance property of an EmbeddedDocument in post_init method
I'm trying to get parent document (mongoengine.Document) of an EmbeddedDocument and, as suggested here I'm using self._instance.
I'm trying to get this attribute in post_init method, but it doesn't ...
0
votes
0
answers
29
views
Flask MongoDB - prevent multiple concurrent calls to an endpoint by the same user
We have a Flask + MongoDB web application based on MongoEngine. We are trying to enforce a user-level limit in a thread safe manner, meaning we need to prevent multiple concurrent calls to an endpoint ...
0
votes
0
answers
22
views
automatic many to many relationship in mongoengine
i'm trying to create a e-shop like site, i'm using two models, Product and User. My current problem relays in the fact that when creating new products, those new products needs to be manually inserted ...
0
votes
0
answers
12
views
Is passing additional data to save() the right way to store the results of logic triggered by a POST?
I've got a django rest framework view that passes data from a POST to another function that returns a result.
I want to store that result in the database so that you can GET a previous result or ...
0
votes
0
answers
16
views
The Django serializer for MongoDB does not display data correctly
So, I have 2 models, Flow and Step.I want when the Flows to be displayed, and the Steps corresponding to this Flow should also be displayed, something that doesn't happen even though it should(I want ...
0
votes
0
answers
11
views
How can I call create a case-insensitive regex for mongoengine query builder?
I have a collection of stock tickers. I am trying to write a query so user can find a stock, lets say AAPL whether she enters AAP or aapl or AaPL
So, far I am able to generate a regex so user is able ...
0
votes
1
answer
25
views
Flask MongoDB How to sort string field with integer values?
I have a model
class Ticket(db.Document):
created = db.DateTimeField(default=datetime.utcnow)
ticket_number = db.StringField(unique=True)
I have ticket_number with integer values but stored ...
0
votes
0
answers
16
views
In MongoEngine is there a way to override the hash function used by add_to_set? I would only like some specific object properties to be used for set
In my MongoEngine ORM I have an embedded document that looks like this:
class Aggregate(EmbeddedDocument):
date = StringField(required=True)
quote = DictField()
I am adding this aggregate ...
0
votes
0
answers
10
views
Using MongoEngine, how may I avoid duplicate values in a list of embedded documents?
I have a MongoDB schema to save stock quotes. I am trying to avoid having duplicate dates in the schema:
The schema looks like this:
[
{
_id: ObjectId("63887965a3dace05f0a336db"),
...
0
votes
0
answers
11
views
MongoEngine - Help in converting a query
I have a working query that I would like to convert to MongoEngine.
MongoDB query: db.collection.find({'actions.type':'type1','actions.date':{'$lte':ISODate('2022-11-28T02:09:12.045233')}})
I tried ...
0
votes
1
answer
29
views
Cannot deserialize properly a response using pymongo
I was using an API that were written in NodeJS, but for some reasons I had to re-write the code in python. The thing is that the database is in MongoDB, and that the response to all the queries (with ...
0
votes
1
answer
94
views
MongoEngine cannot connect through Atlas Uri string. Tried everything
I'm new to programming and am building my first app.. I'm building a kivy app trying to use mongoDB as the database. I can connect to a localhost to query and create documents. I cannot get it to ...
0
votes
0
answers
19
views
MongoEngine ListField of ReferenceFields
I'm trying to create many-to-many relations with mongoengine as discussed in here
using a ListField of ReferenceField(s).
When removing an existing element from the database that's being referenced, ...
0
votes
0
answers
29
views
How would I append to a list of EmbeddedDocuments inside another list of EmbeddedDocuments?
Model overview:
from flask_login import current_user...
from flask_mongoengine import MongoEngine
...
db = MongoEngine()
class Comment(db.EmbeddedDocument):
text = db.StringField()
...
...
0
votes
0
answers
22
views
Sorting a ListField containig ReferenceFields in MongoEngine
I am currently trying to Combine a SortedListField in MongoEngine with a ReferenceField. Unfortunately, this doesn't seem to be possible.
Let's suppose I have a class/document called game which has a ...
0
votes
1
answer
31
views
How can I find if any user with given ID exists on an array of arrays using flask and mongoengine?
I have a collection with multiple Course documents. On it, i have an array of course_users like the following example:
Like this, I can have multiple courses in the same collection.
My purpose is to ...
0
votes
1
answer
24
views
How can I transpose a list of documents in MongoDB?
I have a document like:
{
"_id": "6345e01473144cec0073ea95",
"results": [
{"total_cost": 10, "total_time": 20},
{"...
0
votes
0
answers
13
views
MongoEngine document IntField with default not saved properly
Im using MongoEngine (0.24.2) to setup my documents on the MongoDB server (5.0).
When using an IntField with a default value I noticed that the field doesn't get saved to my document depending on how ...
0
votes
0
answers
31
views
Mongoengine: Save not working - but PyMongo insert_one() works on same model
I am having trouble getting mongoengine's .save() to actually save a new document, but I'm able to save the same document via pymongo.insert_one(). My model class is.
class BlotterItem(me.Document): ...
0
votes
0
answers
36
views
Mongoengine + Python Class __init__
I'm new to MongoEngine , and trying to integrate it within a larger python application.
Can you initialize MongoEngine inheriting-document-classes with a super().init?
And does every class attribute ...
0
votes
0
answers
31
views
insert pandas dataframe into mongodb with mongoengine
I have some dataframe df, example below
How do I insert the df using mongoengine?
illustration: date contents
0 2022-04-20 lorem ipsum
1 2023-04-20 ...
1
vote
2
answers
91
views
mongoengine query for duplicates in embedded documentlist
I'm making a python app with mongoengine where i have a mongodb database of n users and each user holds n daily records. I have a list of n new record per user that I want to add to my db
I want to ...
0
votes
0
answers
95
views
MongoEngine converts a class that inherits from dict into a BaseList in the from_json method
I want to save pydantic models in my mongo database, so I made a custom field that inherits from DictField:
class BaseModelField(DictField):
"""
A pydantic BaseModel field. ...
0
votes
0
answers
42
views
append() doesnt work EmbeddedDocumentListField (mongoengine)
I worked with python a lot but I'm new to mongoengine.I saw in a tutorial someone using the append() method to add an item to a EmbeddedDocumentListField.
unfortunately, I didn't manage to add a new ...
0
votes
0
answers
19
views
remove '$oid' property from mongo document python flask
I'm using MongoEngine, my query is:
user = User.objects(_id = payload['userId']).exclude('password').first()
print(user) outputs the following in terminal
{'_id': {'$oid': '6331cbb82d45971a0e51c066'},...
0
votes
0
answers
35
views
How to save document using classmethod with mongoengine
I try to use class method in mongoengine to define a method that hash the password and write data to mongodb, then call the method outside the class, here is my code
model.py
from mongoengine import ...
0
votes
0
answers
31
views
Abstract class - MongoEngine
Per MongoEngine docs (http://docs.mongoengine.org/guide/defining-documents.html#abstract-classes:~:text=document._data%20dictionary.-,2.3.9.%20Abstract%20classes,-If%20you%20want) abstract classes is ...
0
votes
0
answers
29
views
How can I push to every item of an array of arrays with mongoengine?
I have the following document on MongoDB:
My intention is to push a new exams_eval for every student item into students Array. I don't really know how to do this because is so embedded (course....
0
votes
1
answer
21
views
Mongoengine How to Filter with ISODate
I'm trying to convert a query string into Mongoengine. The filter is looking at an array to limit to a lifecycle match and enable_date is null or enable_date is less than or equal to an ISODate
filter ...
1
vote
0
answers
131
views
Django + Mongoengine - settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details
And here I am again.
I am trying to connect my app to MongoDB as I want to implement a non-rel database. The application works fine with SQL3Lite and I was also able to use Djongo. Yet, I am planning ...
0
votes
0
answers
48
views
Alternate Values for MongoDB fields setup via Mongoengine
I have a somewhat different need/requirement in how I use mongoengine and wanted to share the below to get any ideas on how to deal with it.
My requirement is that for some fields in a document, I ...
0
votes
0
answers
19
views
mongoengine.save not actually saving to db?
We use mongouse version 0.4.2 and have a piece of code that looks like this:
from mongoengine import Document
class Job(Document):
.....
def create_and_save_job(cls, my_data):
try:
...
0
votes
0
answers
29
views
Mongoengine query "icontains" string for subfield
Example Mongodb Document
[
{
"_id": {
"$oid": "62f37c3fd9f533fc248c3dcb"
},
"statistics": "default value"
...
0
votes
0
answers
26
views
Test Database is Not substituing the production db when testing in FastAPI
I was deploying my fastapi application to github using CI/CD,and it was running the job and gave an error,that a default connection was not defined (in this app I am using FastAPI to the api itself,...
1
vote
0
answers
173
views
MongoDB - Connections vs. sessions
I tried to understand what is the difference between connection and session upon mongoDB connection. I do understand that sessions are stored in cache on the db side, and cleaned up per 5 minutes (...
0
votes
0
answers
13
views
How to store User interactions related to a post in terms of optimum performance in MongoDB?
The most frequent query is going to be about How the Human Interacted with the post like did he liked it or not, how many times the Post was on the newsfeed and at what times the post was on the ...
0
votes
1
answer
35
views
is it possible to search null objects in mongoengine?
I'm trying to search null object with python NoneType but got the below error message:
raise ValidationError(message, errors=errors, field_name=field_name) mongoengine.errors.ValidationError: 'null' ...
0
votes
0
answers
15
views
Update column value in Mongoengine queryset
Query written in MongoDB:
db.collection.update(
{},
[{"$set": {"name": "$first_name"}}]
)
Here dollar($) placeholder is used like $first_name to get the value of ...
0
votes
0
answers
42
views
how unique 2 field together in mongodb timeseries
I am new in mongo DB.
We are using mongoDB for CandleStick information.
I made a time series collection, and this is my index
db.timeseries_test.createIndex(
{
"symbol": 1,
...
0
votes
0
answers
49
views
override mongoengine query mechanism
Let's say that I have 2 mongo collections, being handled using mongoengine at server.
class UserA(Document):
first_name = fields.StringField()
last_name = fields.StringField()
country = fields....
0
votes
0
answers
38
views
Remove element from EmbeddedDocumentList, then delete Document if list is empty. Mongoengine
class Sequence(Document):
seq = StringField(required=True)
abundances = EmbeddedDocumentListField(AbundanceRecord)
class AbundanceRecord(EmbeddedDocument):
sample_id = ObjectIdField(...
0
votes
0
answers
25
views
Can not read file from mongoengine
I have the current class below:
class DeviceConfigBackupEntry(BaseEmbeddedDocument):
backup_date = me.StringField(required=True, max_length=100)
backup_file = me.FileField(required=True)
...