Questions tagged [pymodm]

Use this tag in questions related to the Official Mongodb Python Document Mapper (pymodm)

Official project released by the mongodb python team.

Pymodm is actively maintained on github and has an acceptable documentation

It can be installed using pip:

pip install pymodm

Basic example usage:

from pymodm import MongoModel, fields, connect

connect(mongo_uri)

class Release(MongoModel):
  # _id is generated by the model
  name = fields.CharField(required=True)  
  year = fields.IntegerField(required=True)  
  tracks = fields.ListField( default=[])
26 questions
2
votes
1 answer

Define field in Django which can be of any type

Pymodm is being used to define my model for the MongoDB collection in Django. I want to declare a field that can store values of any type (List, String, or Integer).    from pymodm import MongoModel, fields class DefinitionEntity(MongoModel):    …
Ankit Chouhan
  • 45
  • 1
  • 5
2
votes
1 answer

get first value in Pymodm

I would like to check if the username given during the registration of a user already exists using pymodm with a clear solution similar to this one using pymongo: if users.find_one({"username": username}) is not None: print("This username…
AlixL
  • 372
  • 2
  • 13
2
votes
1 answer

Querying related collection by object in pymodm?

I'm using pymodm for ORM in my project. I have the following simple case: class IdentityRecord(MongoModel): alias = fields.CharField() # normal name for identity class IdentityImage(MongoModel): filename = fields.CharField() # filename…
drsealks
  • 2,282
  • 1
  • 17
  • 34
2
votes
3 answers

How to convert Pymodm objects to JSON?

I am using Pymodm as a mongoDB odm with python flask. I have looked through code and documentation (https://github.com/mongodb/pymodm and http://pymodm.readthedocs.io/en/latest) but could not find what I was looking for. I am looking for an easy way…
Jodo
  • 4,515
  • 6
  • 38
  • 50
1
vote
0 answers

Is there a better way to do a $lookup (ie. a JOIN) with PyMODM QuerySet classes than this?

Model Right now I have two PyMODM Models: class PlaylistTrack(MongoModel): post = fields.ReferenceField(Post, primary_key=True) playlist_position = fields.IntegerField() # Uses zero-indexing class Post(MongoModel): reddit_post_id =…
1
vote
1 answer

MongoDB Unique Compound Index is Allowing Duplicates

I'm using PyMongo and PyMODM to work with a fairly simple document structure. This is what my model is like: class User(MongoModel): subscriber_uid: fields.CharField = fields.CharField(required=True) interface: fields.CharField =…
shaun m
  • 440
  • 1
  • 5
  • 15
1
vote
1 answer

Model of a nested document in pymodm or mongoengine to work in Django

I have a specific kind of JSON which I need to code into a model for my Django problem. Problem is I have nested document in it or should I say object of objects and I don't know how to design the model in Pymodm or Mongoengine. Here is the JSON…
1
vote
1 answer

How can I retrieve data using PyMongo?

I have read the tutorials and because I am using three seperate things: 1. Flask as a server 2. PyMongo as a MongoDB driver 3. PyMODM as a schema creator I got confused already. First, I have defined the Schema using PyMODM: from pymongo import…
Steve Martin
  • 103
  • 6
1
vote
1 answer

Authentication failed error in Python script to connect MongoDB server using pymodm

The MongoDB server is hosted in a docker container. Created a super user with root permission to login using username and password. Using pymodm to connect to MongoDB server from Python script. I'm able to connect to the docker hosted MongoDB server…
Sarabjeet Singh
  • 109
  • 1
  • 13
1
vote
1 answer

PyMODM - Find Document(s)

I'm using PyModm as an ORM layer for MongoDB for my Django CRUD app. I created a MongoModel as in so: class Book(MongoModel): title = fields.CharField(primary_key=True) author = fields.CharField() To create and update documents the pymodm…
Kemeia
  • 826
  • 2
  • 9
  • 24
1
vote
2 answers

Pymodm - Mongodb, How to create an index in a collection

I'm trying to create server side flask session extension that expires after # time. I found below Mongodb shell command in the documentation. db.log_events.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } ) But how can I do it using…
s1n7ax
  • 2,750
  • 6
  • 24
  • 53
1
vote
1 answer

Python - Confusion about importing same module by two other modues

I noticed this while try to create an flask-extension with pymodm. Consider a use case of pymodm.MongoModel. Models.py (user defined medule) #line 1 from pymodm import MongoModel, fields,connect #line…
s1n7ax
  • 2,750
  • 6
  • 24
  • 53
1
vote
1 answer

scrapy hub - exceptions.ImportError: No module named pymodm

I can run my scrapy locally without any issues, however, when i try to run job from scrapinghub i get the following error (connecting to mongo atlas cloud): exceptions.ImportError: No module named pymodm I import using: import pymodm Any help is…
Rodrigo Rubio
  • 1,686
  • 2
  • 16
  • 26
1
vote
1 answer

How to drop MongoDB field using PyMODM and Django

How can I drop/delete a field from the document when it is already created using PyMoDM? I have following model: class User(MongoModel): email = fields.EmailField(required=True) password = fields.CharField(required=True) first_name =…
Kristian
  • 738
  • 6
  • 15
0
votes
1 answer

Deleting a document that matches a query in pymodm

Please help, been stuck for hours, how do I delete a document that matches a query directly in pymodm. For example: user = User.objects.raw({'name':'Moses'}) How do I delete this user from my database collection?
panam-py
  • 1
  • 2
1
2