English 中文(简体)
如何在Mongo“(WHERE)一栏=一栏”?
原标题:How to "(WHERE) column = column" in Mongo?

我喜欢Mongo这样简单的事情,所以我希望利用它来做一些更先进的事情。 在我需要之前,这样做是徒劳的:

UPDATE tbl SET a = b WHERE c <> 0

a = b part is what I can t out. 我尝试了mongodb.org,但我看不到。 页: 1 WHERE a = b,但我无法发现这两种情况。

另一种选择是,所有各行各样,而不是单独更新,但我不喜欢。 它必须更加简单。

感谢。

最佳回答

You want to check the documentation for updating.
http://www.mongodb.org/display/DOCS/Updating

Your code might look like:
db.tbl.update( { c:{$ne:0}}, { $set: { a : b } } );

If you need to brush up on advanced queries (e.g. using $ne), then check here:
http://www.mongodb.org/display/DOCS/Advanced+Queries

EDIT:
Apparently you can t update with data from the same document.
MongoDB: Updating documents using data from the same document

<EDIT 2(用地图压缩):

var c = new Mongo();
var db = c.getDB( db )
var s = db.getCollection( s )
s.drop();
s.save({z:1,q:5});
s.save({z:11,q:55});

db.runCommand({
mapreduce: s ,
map:function(){
  var i = this._id; //we will emit with a unique key. _id in this case
  this._id=undefined; //strange things happen with merge if you leave the id in
  //update your document with access to all fields!
  this.z=this.q;

  emit(i,this);
}, 
query:{z:1},    //apply to only certain documents
out:{merge: s } //results get merged (overwrite themselves in collection)
});

//now take a look
s.find();
问题回答

暂无回答




相关问题
NO-SQL reliable for small business app?

I m deciding between go for a NON-SQL engine or a regular SQL one for a document managment system for small bussines. I have experience with firebird/sql server and found a good track of reliability (...

CouchDB View, Map, Index, and Sequence

I think read somewhere that when a View is requested the "map" is only run across documents that have been added since the last time it was requested? How is this determined? I thought I saw something ...

Cassandra Vs Amazon SimpleDB

I m working on an application where data size and SQL queries are going to be heavy. I am thinking between Cassandra or Amazon SimpleDB. Can you please suggest which is more suitable in this kind of ...

representing a many-to-many relationship in couchDB

Let s say I m writing a log analysis application. The main domain object would be a LogEntry. In addition. users of the application define a LogTopic which describes what log entries they are ...

Riak on Windows

I want to play with Riak http://riak.basho.com/ or a least get it running on a Windows system. I have downloaded the source code and compiled it but that s where I get stuck, how do I start it?

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

热门标签