Insert_one no such method exists @ pymongo 3.7.2
up vote
0
down vote
favorite
I´m pretty new learning Python and all the containing stuff.
I tried to make my first little steps, installing a MongoDB (working) and connecting to it.
from pymongo import MongoClient
from pprint import pprint
from random import randint
client = MongoClient('localhost', 27017)
db = client.test
collection = db.users
user = {"id": 1, "username": "Test"}
user_id = collection.insert_one(user).inserted_id
print(user_id)
This is the complete code.
pymongo Version: 3.7.2 checked with:
pip freeze | grep pymongo
Output: pymongo==3.7.2
Python Version: 3.7.1
If I try to execute my tiny script, the following error occurs:
'Collection' object is not callable.
If you meant to call the 'insert_one' method on a 'Collection'
object it is
failing because no such method exists.
Where is my Fault?
A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"
python pymongo pymongo-3.x
add a comment |
up vote
0
down vote
favorite
I´m pretty new learning Python and all the containing stuff.
I tried to make my first little steps, installing a MongoDB (working) and connecting to it.
from pymongo import MongoClient
from pprint import pprint
from random import randint
client = MongoClient('localhost', 27017)
db = client.test
collection = db.users
user = {"id": 1, "username": "Test"}
user_id = collection.insert_one(user).inserted_id
print(user_id)
This is the complete code.
pymongo Version: 3.7.2 checked with:
pip freeze | grep pymongo
Output: pymongo==3.7.2
Python Version: 3.7.1
If I try to execute my tiny script, the following error occurs:
'Collection' object is not callable.
If you meant to call the 'insert_one' method on a 'Collection'
object it is
failing because no such method exists.
Where is my Fault?
A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"
python pymongo pymongo-3.x
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I´m pretty new learning Python and all the containing stuff.
I tried to make my first little steps, installing a MongoDB (working) and connecting to it.
from pymongo import MongoClient
from pprint import pprint
from random import randint
client = MongoClient('localhost', 27017)
db = client.test
collection = db.users
user = {"id": 1, "username": "Test"}
user_id = collection.insert_one(user).inserted_id
print(user_id)
This is the complete code.
pymongo Version: 3.7.2 checked with:
pip freeze | grep pymongo
Output: pymongo==3.7.2
Python Version: 3.7.1
If I try to execute my tiny script, the following error occurs:
'Collection' object is not callable.
If you meant to call the 'insert_one' method on a 'Collection'
object it is
failing because no such method exists.
Where is my Fault?
A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"
python pymongo pymongo-3.x
I´m pretty new learning Python and all the containing stuff.
I tried to make my first little steps, installing a MongoDB (working) and connecting to it.
from pymongo import MongoClient
from pprint import pprint
from random import randint
client = MongoClient('localhost', 27017)
db = client.test
collection = db.users
user = {"id": 1, "username": "Test"}
user_id = collection.insert_one(user).inserted_id
print(user_id)
This is the complete code.
pymongo Version: 3.7.2 checked with:
pip freeze | grep pymongo
Output: pymongo==3.7.2
Python Version: 3.7.1
If I try to execute my tiny script, the following error occurs:
'Collection' object is not callable.
If you meant to call the 'insert_one' method on a 'Collection'
object it is
failing because no such method exists.
Where is my Fault?
A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"
python pymongo pymongo-3.x
python pymongo pymongo-3.x
asked Nov 8 at 17:51
Exitare
126113
126113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
insert_one according with pymongo documentation exists, for server version >= 3.2...
the use is:
user = {'x': 1}
result = db.test.insert_one(user)
result.inserted_id
more complete explanation about insert_one:
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
ObjectId('54f112defba522406c9cc208')
>>> db.test.find_one({'x': 1})
{u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}
the following below, I executed and works fine:
# importing client mongo to make the connection
from pymongo import MongoClient
print("--- Exemplo pymongo Connection ---")
# Connection to MongoDB
client = MongoClient('localhost', 27017)
# Selection the Database
db = client.python
# Select the collection
collection = db.users
# Set up a document
user = {"id": 1, "username": "Test"}
# insert one document into selected document
result = collection.insert_one(user)
# Selection just one document from collection
#result = collection.find_one()
# removing the document inserted
collection.delete_one(user)
# print the inserted_id
print("inserted_id: ", result.inserted_id)
Pymongo Documentation
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
insert_one according with pymongo documentation exists, for server version >= 3.2...
the use is:
user = {'x': 1}
result = db.test.insert_one(user)
result.inserted_id
more complete explanation about insert_one:
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
ObjectId('54f112defba522406c9cc208')
>>> db.test.find_one({'x': 1})
{u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}
the following below, I executed and works fine:
# importing client mongo to make the connection
from pymongo import MongoClient
print("--- Exemplo pymongo Connection ---")
# Connection to MongoDB
client = MongoClient('localhost', 27017)
# Selection the Database
db = client.python
# Select the collection
collection = db.users
# Set up a document
user = {"id": 1, "username": "Test"}
# insert one document into selected document
result = collection.insert_one(user)
# Selection just one document from collection
#result = collection.find_one()
# removing the document inserted
collection.delete_one(user)
# print the inserted_id
print("inserted_id: ", result.inserted_id)
Pymongo Documentation
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
add a comment |
up vote
1
down vote
insert_one according with pymongo documentation exists, for server version >= 3.2...
the use is:
user = {'x': 1}
result = db.test.insert_one(user)
result.inserted_id
more complete explanation about insert_one:
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
ObjectId('54f112defba522406c9cc208')
>>> db.test.find_one({'x': 1})
{u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}
the following below, I executed and works fine:
# importing client mongo to make the connection
from pymongo import MongoClient
print("--- Exemplo pymongo Connection ---")
# Connection to MongoDB
client = MongoClient('localhost', 27017)
# Selection the Database
db = client.python
# Select the collection
collection = db.users
# Set up a document
user = {"id": 1, "username": "Test"}
# insert one document into selected document
result = collection.insert_one(user)
# Selection just one document from collection
#result = collection.find_one()
# removing the document inserted
collection.delete_one(user)
# print the inserted_id
print("inserted_id: ", result.inserted_id)
Pymongo Documentation
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
add a comment |
up vote
1
down vote
up vote
1
down vote
insert_one according with pymongo documentation exists, for server version >= 3.2...
the use is:
user = {'x': 1}
result = db.test.insert_one(user)
result.inserted_id
more complete explanation about insert_one:
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
ObjectId('54f112defba522406c9cc208')
>>> db.test.find_one({'x': 1})
{u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}
the following below, I executed and works fine:
# importing client mongo to make the connection
from pymongo import MongoClient
print("--- Exemplo pymongo Connection ---")
# Connection to MongoDB
client = MongoClient('localhost', 27017)
# Selection the Database
db = client.python
# Select the collection
collection = db.users
# Set up a document
user = {"id": 1, "username": "Test"}
# insert one document into selected document
result = collection.insert_one(user)
# Selection just one document from collection
#result = collection.find_one()
# removing the document inserted
collection.delete_one(user)
# print the inserted_id
print("inserted_id: ", result.inserted_id)
Pymongo Documentation
insert_one according with pymongo documentation exists, for server version >= 3.2...
the use is:
user = {'x': 1}
result = db.test.insert_one(user)
result.inserted_id
more complete explanation about insert_one:
>>> db.test.count_documents({'x': 1})
0
>>> result = db.test.insert_one({'x': 1})
>>> result.inserted_id
ObjectId('54f112defba522406c9cc208')
>>> db.test.find_one({'x': 1})
{u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}
the following below, I executed and works fine:
# importing client mongo to make the connection
from pymongo import MongoClient
print("--- Exemplo pymongo Connection ---")
# Connection to MongoDB
client = MongoClient('localhost', 27017)
# Selection the Database
db = client.python
# Select the collection
collection = db.users
# Set up a document
user = {"id": 1, "username": "Test"}
# insert one document into selected document
result = collection.insert_one(user)
# Selection just one document from collection
#result = collection.find_one()
# removing the document inserted
collection.delete_one(user)
# print the inserted_id
print("inserted_id: ", result.inserted_id)
Pymongo Documentation
edited Nov 8 at 18:33
answered Nov 8 at 18:05
Sham Fiorin
208
208
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
add a comment |
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
1
1
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
Thanks for the Hint. I solved it.
– Exitare
Nov 8 at 18:12
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213476%2finsert-one-no-such-method-exists-pymongo-3-7-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown