it seems move existing code that use a rdms (sqlite, mysql, postgresql) to mongodb need an extra effort.
e.g.
DAL connection from book
>>> db = DAL('mongodb://user:password@localhost/connect_test')
Error:
...
OperationFailure: command SON([('authenticate', 1), ('user', u'user'), ('nonce', u'7f46671524655a7d'), ('key', u'2be426ffba7c067a8a4ddb2a5e5056bf')]) on namespace connect_test.$cmd failed: auth failed
Solution:
1. without mongodb user and password
db = DAL('mongodb://localhost/connect_test')
or
2. create mongodb user and password in terminal shell
cat <<EOL > userMongoDB.js
use connect_test
db.createUser(
{
user: "username",
pwd: "password",
roles: [ { role: "dbAdmin", db: "connect_test" },
{ role: "userAdmin", db: "connect_test" } ]
}
)
EOL
mongo test < userMongoDB.js
Date not str
>>> db.table0.insert(date0 = "2017-01-01", datetime0 = "2017-01-01 00:00:00")
Error:
...
TypeError: combine() argument 1 must be datetime.date, not str
Solution (strange that datetime field type didn't get affected by an error traceback):
from datetime import datetime
db.table0.insert(date0 = datetime.strptime('2017-01-01', '%Y-%m-%d'), datetime0 = "2017-01-01 00:00:00")
Iterselect
>>> rows = db().iterselect(db.table0.ALL)
Error:
...
AttributeError: 'Mongo' object has no attribute 'iterselect'
Solution:
rows = db().select(db.table0.ALL)
not sure is there any difficulties i'll face during the moving, but grateful a lot things to learn from obstacles.