伪代码:
const mongoose = require('mongoose');
const { Schema } = mongoose;
const UserSchema = new Schema({
username: String
});
mongoose.model('User', UserSchema);
const con = mongoose.connect(config.uri, config.options, (err) => {
if(err) throw err;
const User = con.model('User');
User.db.db.command({ testProcedure: 1 }, console.log);
})
错误输出:
{ MongoError: Command is not supported
at /home/username/git/project/node_modules/mongodb-core/lib/connection/pool.js:580:63
at authenticateStragglers (/home/username/git/project/node_modules/mongodb-core/lib/connection/pool.js:503:16)
at Connection.messageHandler (/home/username/git/project/node_modules/mongodb-core/lib/connection/pool.js:539:5)
at emitMessageHandler (/home/username/git/project/node_modules/mongodb-core/lib/connection/connection.js:309:10)
at TLSSocket.<anonymous> (/home/username/git/project/node_modules/mongodb-core/lib/connection/connection.js:452:17)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at TLSSocket.Readable.push (_stream_readable.js:208:10)
at TLSWrap.onread (net.js:607:20)
_t: 'OKMongoResponse',
ok: 0,
code: 115,
errmsg: 'Command is not supported',
'$err': 'Command is not supported',
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: {} } null
目标是在MongoDB中执行以下操作(链接转到其自己的node.js SDK):
答案 0 :(得分:2)
存储过程和UDF是本机SQL(DocumentDB)API和关联的SDK的方面。 MongoDB SDK(或专为与MongoDB配合使用的框架,例如您正在使用的Mongoose)对Cosmos DB的存储proc或UDF一无所知。
您需要使用特定语言的Cosmos DB SDK来利用这些优势。但是,我怀疑它们是否可以对使用MongoDB API设置的数据库正常工作。