Ich versuche ein Dokument in einer Sammlung zu finden. Ich habe diese Abfragestruktur in fast allen meinen Sammlungen verwendet, aber aus irgendeinem Grund funktioniert das nicht für diese Sammlung. Irgendeine Hilfe?MongoDB find() findet nicht, was ich brauche
Die einzigen Daten, die in dieser Sammlung jetzt [ { _id: 581757143389e565b5cf8124, companyProfileID: '86660a5b-7f61-4238-889d-1cc3087947b9', url: 'sentsoftware.com', appID: 1 } ]
Query-Struktur:
function getCompany(companyUrl, app, callback) {
\t MongoClient.connect(url, function(err, db) {
\t \t if (err) {
\t \t \t console.log(err);
\t \t } else {
\t \t \t console.log("We are connected");
\t \t }
\t \t
\t \t var collection = db.collection('Companies');
\t \t collection.find({url: companyUrl, appID: app}).toArray(function (err, result) {
\t \t \t if (err) {
\t \t \t \t console.log(err);
\t \t \t \t callback(err);
\t \t \t } else if (result.length) {
\t \t \t \t console.log("found");
\t \t \t \t callback(result);
\t \t \t } else {
\t \t \t \t console.log("No document found");
\t \t \t \t callback(err);
\t \t \t }
\t \t });
\t });
}
Ich halte kein Dokument gefunden zu bekommen. Aber wenn ich den , appID: app
Teil herausnehmen würde, findet es das Dokument.
Übergeben Sie 'App' als' Nummer'? So ist es in der Datenbank gespeichert. – robertklep
Vielleicht ist es ein String-gegen-Nummer-Problem. Sind Sie auf der Suche nach 1 oder "1" –
Ja, ich gebe es als eine Nummer. Ich änderte es zu einer Schnur und es fand es sofort. Vielen Dank! Jemand Post als Antwort und Ill akzeptiere es –