Frage

Ich habe das folgende Bit JS in einem Knoten/Mongoose -Projekt. Ich arbeite an einer automatischen Form. Es funktioniert gut mit einem normalen "Fund", aber ich möchte stattdessen einen "ausgeprägten" Fund machen.

Hier bin ich also so weit. Das Problem, das ich glaube, ist in der Art und Weise, wie die Abfrage gebildet wird. Kann jemand bei meiner Syntax in der unterschiedlichen Linie helfen? Oder ist es nur so, dass die "Unterscheidung" von Mongoose Regex in einer optionalen Abfrage nicht unterstützt?

var text.term = 'johnny';
var regex = new RegExp("^"+text.term);
// execute the search
Performance.collection.distinct({lc_actor: regex}, function(err, docs) {
    var names = [];
    for(var nam in docs) {
        // push the lc_actor to the array
    names.push(docs[nam].lc_actor);
    }
    // send back via callback function
    callback(null, names);
});

Und hier ist, was meine Mongoose-Konsole von Super-Verbose (-vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvre Ambose zeigt:

Tue Nov 29 13:34:30 [conn1] runQuery called mydb.$cmd { distinct: "performances", query: {}, key: { lc_actor: /^johnny/ } }
Tue Nov 29 13:34:30 [conn1] run command mydb.$cmd { distinct: "performances", query: {}, key: { lc_actor: /^johnny/ } }
Tue Nov 29 13:34:30 [conn1] command mydb.$cmd command: { distinct: "performances", query: {}, key: { lc_actor: /^johnny/ } } ntoreturn:1 reslen:140 526ms

Irgendwelche Ideen?

War es hilfreich?

Lösung

Beantwortung meiner eigenen Frage. Ich hatte in der Tat Syntaxfehler in der unterschiedlichen Methode von Mongoose. Es akzeptiert 3 Paramente, ich hatte nur 2. die richtige Syntax mit einem Regex (oder einer beliebigen Bedingung) ist:

Performance.collection.distinct('lc_actor', {lc_actor: regex}, function(err, docs) {

Aus Mongoose -Dokumenten für modell.distinct ():

Model.distinct(field, conditions, callback);

http://mongoosejs.com/docs/finding-documents.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top