0

私はmongodbで一般的な機能を持っています。

db.system.js.save({_id: "Apps",value : function (doc, targetCollection) {

    while (1) {

        var cursor = db.targetCollection.find( {}, { App_id: 1 } ).sort( { _id: -1 } ).limit(1);

        var seq = cursor.hasNext() ? cursor.next().App_id + 1 : 1;

        doc.App_id = seq;

        db.targetCollection.insert(doc);

        var err = db.getLastErrorObj();

        if( err && err.code ) {
            if( err.code == 11000 /* dup key */ )
                continue;
            else
                print( "unexpected error inserting data: " + tojson( err ) );
        }

        break;
    }
}
}); 

nodejsを介してmongooseを使用して、この関数をmongodbに保存する必要があります。

これを行うのを手伝ってください。

4

1 に答える 1