How to perform this query in mongoose?

48 Views Asked by At

Say, I have a collection of files, each file has path. I want to query all files at depth 2. Because the Db may contain a lot of files, I want to filter them on the server and not on the client. Basically I want something like the below, which obviously doesn't work

var FileSchema = new Schema({
      path:String
});
var File = mongoose.model('File', FileSchema);

File
.find()
.where('path.split("/").length == 2')
.exec(function(err, files) {
...
});
0

There are 0 best solutions below