Questions tagged [flask-pymongo]

75 questions
6
votes
6 answers

Pymongo: Best way to remove $oid in Response

I have started using Pymongo recently and now I want to find the best way to remove $oid in Response When I use find: result = db.nodes.find_one({ "name": "Archer" } And get the response: json.loads(dumps(result)) The result would be: { "_id":…
KitKit
  • 8,549
  • 12
  • 56
  • 82
6
votes
1 answer

Flask PyMongo string back to ObjectID

I am using flask with pymongo and I have a case where my Object Id is being converted into a string. How can I change it back to an Object Id so I can use if for querying ? From : 59d7ef576cab3d6118805a20 type is To:…
Max Powers
  • 1,119
  • 4
  • 23
  • 54
3
votes
2 answers

Flask-PyMongo - init_app() missing 1 required positional argument: 'app'

i am trying to initialise my db using flask-pymongo. But i get the following error, File "run.py", line 22, in app = create_app("config") File "run.py", line 11, in create_app mongo.init_app(app) TypeError: init_app() missing 1 required…
Kay
  • 17,906
  • 63
  • 162
  • 270
3
votes
1 answer

Can not import mongo object in other file

Using flask-restful, i can not import the object mongo = PyMongo() from the file app/__init__.py into app/common/db.py. My folder structure looks like this: myproject/ run.py app/ __init__.py config.py common/ …
2
votes
0 answers

send_file from flask pymongo not working for images

I'm trying to make a simple example for sending and receiving files to a mongo db and I can see the images being uploaded correctly to mongodb using mongodbcompass, but I get a type error when I try to retrieve the file and show it. Any help is…
WKGuy
  • 79
  • 7
2
votes
2 answers

Updating a nested record in mongodb array when you don't know the document index

I want to update the record of a nested document, my document looks like this: [ { "_id": "60753fd9b249ad0dfa1eeb48", "name": "Random Name 1", "email": "randomname1@zmel.kom", "likings": [ { "breakfast": { …
Yashasvi Bhatt
  • 325
  • 3
  • 14
2
votes
1 answer

retryWrites in mongodb python

I use pymongo to implement mongo database. I am trying to use the sessions and transactions for the management of operations, but I encountered this error: pymongo.errors.OperationFailure: This MongoDB deployment does not support retryable writes.…
2
votes
0 answers

creating a model with flask-pymongo

I'm very new to MongoDb and I want to try it with a small Flask project. And I picked a PyMongo. But I have no idea how to create a model. And can't find any information on this topic. So I try this: app.config["MONGO_URI"] =…
2
votes
1 answer

Flask Pymongo Insert returns a collection object rather than _id

I'm just getting started with Flask_Pymongo (and pymongo in general). I wrote a simple test route that successfully inserts to my mongo db, however the return is not as expected. If I'm not mistaken pymongo should return the _id field if I call…
Marlone
  • 79
  • 2
  • 8
2
votes
1 answer

Skip and Limit for pagination for a Mongo aggregate

I am working on pagination in flask(Python framework) using flask-paginate (just for ref) I am able to achieve pagination for just a find query as below: from flask_paginate import Pagination from flask_paginate import get_page_args def…
KcH
  • 3,302
  • 3
  • 21
  • 46
2
votes
1 answer

Flask with AWS DocumentDB

I am trying to connect to my AWS DocumentDB using flask and flask_pymongo. TLS is enabled for my AWS cluster. I am able to connect to the DB using the python shell and just pymongo but when I do the below in flask I can't get it to connect. The URI…
yoyoyoyo123
  • 2,362
  • 2
  • 22
  • 36
2
votes
1 answer

Correct way to get a mongo instance in blueprints Flask

I have 3 blueprints in a flask app and the dir structure is like: main/ __init__.py books/ users/ authors/ apps/ Every package inisde main is a blueprint. In my main/__init__.py i have from flask import Flask from flask_pymongo…
anekix
  • 2,393
  • 2
  • 30
  • 57
2
votes
6 answers

Flask-PyMongo - Object of type InsertOneResult is not JSON serializable

i have an api and i am trying to store/post a user object using Flask-Pymongo. but, i get the following error File "/home/kay/.local/share/virtualenvs/server-iT4jZt3h/lib/python3.7/site-packages/flask/json/i│ nit.py", line 321, in jsonify │ …
Kay
  • 17,906
  • 63
  • 162
  • 270
2
votes
1 answer

How to share a flask-pymongo instance in the api routes handler

I am trying to design a simple api using flask, flask-restplus, and flask-pymongo but I'm facing one structural design, based on import and variables sharing, I cannot get access to the db in any way. Here is my code in my main engine file: app =…
Mumrau
  • 62
  • 7
1
vote
1 answer

How to find the max length of an array from a set of documents present in a collection in MongoDB?

I have 'n' number of documents present inside a collection in MongoDB. Structure of those documents is as follows: { "_id": "...", "submissions": [{...}, ...] } I want to find the document which has the highest number of submissions out of…
Anuj Panchal
  • 391
  • 3
  • 15
1
2 3 4 5