mongo query - 返回字段1的值,其中字段2的值为x

时间:2016-06-09 14:38:03

标签: mongodb

我想只返回DOCUMENT ID = 10

的NAME值

以下是我的数据:

echo '<form action="" method="post">
  Menu name:<input type="text" name="mname"><br>
  <select name="any_name">';
$q = mysql_query("SELECT * FROM menu");
while ($row = mysql_fetch_array($q)) {
    $menu_name = $row['menu_name'];
    echo '<option value="'.$menu_name.'">'.$menu_name.'</option>';
}
echo '</select><br>
  <input type="submit" name="submit" value="Add Menu">
</form>';



if (isset($_POST['submit'])) {
    echo $mname = $_POST['mname'];
    echo $select_option_name = $_POST['any_name'];
}

这是我试图运行的查询:

{ "_id" : ObjectId("1"), "DOCUMENT ID" : 10, "NAME" : "Peter", DATE" : "01/1/2016" }
{ "_id" : ObjectId("2"), "DOCUMENT ID" : 10, "NAME" : "Mary", DATE" : "02/1/2016" }
{ "_id" : ObjectId("3"), "DOCUMENT ID" : 10, "NAME" : "Kate", DATE" : "03/1/2016" }
{ "_id" : ObjectId("3"), "DOCUMENT ID" : 20, "NAME" : "Bob", DATE" : "03/1/2016" }
{ "_id" : ObjectId("3"), "DOCUMENT ID" : 20, "NAME" : "Sam", DATE" : "03/1/2016" }
{ "_id" : ObjectId("3"), "DOCUMENT ID" : 30, "NAME" : "Jenny", DATE" : "03/1/2016" }

这是错误:

db.collection.find({"DOCUMENT ID":10},{"NAME"})

如何编写查询,以便只给出ID为10的名称?

0 个答案:

没有答案