lealone / Lealone

比 MySQL 和 MongoDB 快10倍的 OLTP 关系数据库和文档数据库
Other
2.48k stars 519 forks source link

pymongo 和nodejs mongodb 报错 #208

Closed mervynzhang closed 1 year ago

mervynzhang commented 1 year ago
import datetime
from pymongo import MongoClient
client = MongoClient("mongodb://localhost:27017/")
db = client.test
collection = db.test_collection
post = {
    "author": "Mike",
    "text": "My first blog post!",
    "tags": ["mongodb", "python", "pymongo"],
    "date": datetime.datetime.now(tz=datetime.timezone.utc),
}
posts = db.posts
post_id = posts.insert_one(post).inserted_id
print(post_id)

报错

14:34:02.336 [ScheduleService-4] ERROR org.lealone.plugins.mongo.server.MongoServerConnection - send error
org.bson.BsonInvalidOperationException: Value expected to be of type STRING is of unexpected type ARRAY
        at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.bson.BsonValue.asString(BsonValue.java:69) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.bson.BsonBase.toValue(BsonBase.java:52) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.bson.BsonBase.toValueExpression(BsonBase.java:80) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.bson.command.BCInsert.addRows(BCInsert.java:57) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.bson.command.BCInsert.execute(BCInsert.java:33) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.bson.command.BsonCommand.execute(BsonCommand.java:216) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.server.MongoTask.run(MongoTask.java:44) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.SessionInfo.runTask(SessionInfo.java:103) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.SessionInfo.submitTask(SessionInfo.java:66) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.server.MongoServerConnection.handleCommand(MongoServerConnection.java:249) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.server.MongoServerConnection.handleMessage(MongoServerConnection.java:231) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.plugins.mongo.server.MongoServerConnection.handle(MongoServerConnection.java:185) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.net.nio.NioEventLoop.read(NioEventLoop.java:258) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.net.nio.NioEventLoop.handleSelectedKeys(NioEventLoop.java:475) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.Scheduler.runEventLoop(Scheduler.java:504) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.Scheduler.run(Scheduler.java:135) [lealone-6.0.0-SNAPSHOT.jar:?]
mervynzhang commented 1 year ago

nodejs

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
const client = new MongoClient(url);

const myDB = client.db("myDB");
const myColl = myDB.collection("pizzaMenu");

const doc = { name: "Neapolitan pizza", shape: "round" };
const result =  myColl.insertOne(doc);
console.log(
   `A document was inserted with the _id: ${result.insertedId}`,
);

报错

14:45:10.037 [ScheduleService-6] ERROR org.lealone.plugins.mongo.server.MongoServerConnection - send error
org.lealone.common.exceptions.JdbcSQLException: Data conversion error converting "X'654345768110a6684f7ebc0d' (PIZZAMENU: _ROWID_ BIGINT)"; SQL statement:
 -- row #2 ('Neapolitan pizza', 'round', X'654345768110a6684f7ebc0d') [22018-0]
        at org.lealone.common.exceptions.DbException.getJdbcSQLException(DbException.java:342) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.common.exceptions.DbException.get(DbException.java:173) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.common.exceptions.DbException.get(DbException.java:150) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.db.table.Column.convert(Column.java:154) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.sql.dml.MerSert$YieldableMerSert.createNewRow(MerSert.java:209) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.sql.dml.MerSert$YieldableMerSert.executeLoopUpdate0(MerSert.java:183) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.sql.dml.MerSert$YieldableMerSert.executeLoopUpdate(MerSert.java:176) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.sql.executor.YieldableLoopUpdateBase.executeInternal(YieldableLoopUpdateBase.java:31) ~[lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.sql.executor.YieldableBase.run(YieldableBase.java:115) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.db.session.ServerSession$YieldableCommand.run(ServerSession.java:1306) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.Scheduler.executeNextStatement(Scheduler.java:308) [lealone-6.0.0-SNAPSHOT.jar:?]
        at org.lealone.server.Scheduler.run(Scheduler.java:134) [lealone-6.0.0-SNAPSHOT.jar:?]
codefollower commented 1 year ago

MongoDB 插件还在逐步完善,如果报错就是还没有实现的功能。

codefollower commented 1 year ago

第一个错误是数组转成字符串出错了,第二个错误是 _id 字段目前只支持数字,nodejs 自动生成的 _id 是二进制。这两个后续就会解决。