Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Grails MongoDB低级Api插入和获取最后一个id的正确方法_Mongodb_Grails - Fatal编程技术网

使用Grails MongoDB低级Api插入和获取最后一个id的正确方法

使用Grails MongoDB低级Api插入和获取最后一个id的正确方法,mongodb,grails,Mongodb,Grails,我正在尝试使用低级api将文档插入mongodb。这很好,但我需要身份证 def lesson = db.lesson.insert([ description: "This is a lesson", title: title, name: name, lessonVers

我正在尝试使用低级api将文档插入mongodb。这很好,但我需要身份证

def lesson = db.lesson.insert([
                            description: "This is a lesson",
                            title: title,
                            name: name,
                            lessonVersion: "1.0",
                            active: true
                    ])

我应该如何进行插入,以便获得_id或整个文档。我试图使用低级api,因为我需要许多动态字段。我知道你可以用域对象来做这件事,但是你想试试这个方法。

只要在它后面使用db.lesson.findOne()就可以得到文档并得到它的id,在“\u id”上的defaul ist desc,所以最新的id是来自最后一个插入的,这就更好了!在插入后,使“println课”和def课现在保持id!id是客户端生成的,因此您不必询问服务器