添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I am using $graphlookup with mongoose , it is working fine in mongoplay ground but in nodejs it is not giving tree structure data. Instead it is giving
TreeResult as empty array
Please find the below details:
below is the my method in nodejs
JavaScript
<pre> folder_tree_structure: async (ctx:any) => { try { const treeStructure = await FileFolder.aggregate([ $match: { parentFolder: { $exists: true $graphLookup: { from : " FileFolder" , startWith: " $_id" , connectFromField: " parentFolder" , connectToField: " parentFolder" , maxDepth: 1 , depthField: " depth" , as: " TreeResult" console .log( ' tree structure' ,treeStructure ) ctx.status = 200 ; ctx.body = treeStructure; } catch (err) { ctx.response.status( 500 ).send(err); and my mongoose schema:
const fileFolderSchema = new Schema({ name: String , parentFolder: {type: Mongoose.Types.ObjectId, ref : " FileFolder" }, path: String , metadata: { type: metaDataSchema }, { id: false }). set ( ' toJSON' , { virtuals: true export const FileFolder = Mongoose.model( ' FileFolder' , fileFolderSchema);
What I have tried:
Here you can find what I have tried in mongo playground:
Mongo playground [ ^ ]
and the output when I tried in nodejs
" _id" : " 6360468045689c3d0c70e53c" , " name" : " Folder1" , " path" : " files/Folder1" , " metadata" : { " version" : 1, " created_by" : " user-1" , " created_on" : " 2022-10-31T22:04:48.233Z" " __v" : 0, " parentFolder" : " 6360468045689c3d0c70e53c" , " TreeResult" : [] " _id" : " 6360468d45689c3d0c70e558" , " name" : " Folder2" , " path" : " files/Folder2" , " metadata" : { " version" : 1 , " created_by" : " user-1" , " created_on" : " 2022-10-31T22:05:01.787Z" " __v" : 0 , " parentFolder" : " 6360468045689c3d0c70e53c" , " TreeResult" : [] " _id" : " 6360469445689c3d0c70e55c" , " name" : " Folder3" , " path" : " files/Folder3" , " metadata" : { " version" : 1 , " created_by" : " user-1" , " created_on" : " 2022-10-31T22:05:08.309Z" " __v" : 0 , " parentFolder" : " 6360468d45689c3d0c70e558" , " TreeResult" : [] " _id" : " 636a732946b670e689afd454" , " name" : " images" , " path" : " files/images" , " metadata" : { " version" : 1 , " created_by" : " user-1" , " created_on" : " 2022-11-08T15:18:01.190Z" , " timeout" : -1 " __v" : 0 , " parentFolder" : " 6360468045689c3d0c70e53c" , " TreeResult" : [] " _id" : " 636a735f46b670e689afd46d" , " name" : " images" , " path" : " files/images" , " metadata" : { " version" : 1 , " created_by" : " user-1" , " created_on" : " 2022-11-08T15:18:55.764Z" , " timeout" : -1 " __v" : 0 , " parentFolder" : " 6360468d45689c3d0c70e558" , " TreeResult" : []
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •