--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Note .We do not recommend using server-side stored functions if possible.
--
--
We are looking at a very busy usage of Mongo, so every bit of free network traffic will be good.
It is too bad one can't create a JS function on the server side of Mongo to basically pull data together with a number of queries (i.e. simulating joins?), to return a single result. It seems there must be a benefit, when the client can do less querying to get the same result, when the network is being pushed to the limit, than have the client side have the logic and have to send out numerous queries for a standard request for data.
I know, don't try to make Mongo what it isn't, an RDBMS, but still. :)I can't think of an app that doesn't need relationships within its data and it is a fact of MongoDB life that relationships must exist too. Gathering data, because of those relationships is monumentally important to any application. I don't think it is right when I here, "If you need to join data, don't use Mongo." You might as well just say, "Don't use Mongo at all, if you have an even moderately complex application." Or, "Just use Mongo, if you have a simple applications for it." That isn't the truth I think, because I am sure it isn't what the MongoDB guys set out to make and Mongo is being used by a good number of fairly complex applications anyway. Right? So why not improve even more on the ability to join information smartly within the DB? Is it really an architectural or basic conceptual problem? We aren't talking schema here. We are talking data relationships and "No-Sql" simply cannot mean "no relationships" or poor relationships. I aint buying it.:)
> db.dept.save( {_id: 1, name: 'Sales'} );
> db.dept.save( {_id: 2, name: 'Marketing'} );
> db.dept.save( {_id: 3, name: 'Support'} );
> db.emp.save( { _id: 1, name: 'Ben', dept: 1 } );
> db.emp.save( { _id: 2, name: 'William', dept: 3 } );
> db.emp.save( { _id: 3, name: 'Jenna', dept: 3 } );
> db.emp.save( { _id: 4, name: 'Steven', dept: 3 } );To make this efficient, I'll create a secondary index on the 'dept' field in the 'emp' collection, and the 'name' field in the 'dept' collection:
> db.emp.ensureIndex( dept: 1 );
> db.dept.ensureIndex( name: 1 );
By default, there are already indexes on "dept._id" and "emp._id".
To find all of the employees in the "Support" department, I need to do two queries in an application-level join:
> result = db.dept.findOne({name: 'Support'}, {_id:1} );
{ "_id" : 3 }
> desired_dept = result["_id"];
3
> db.emp.find( { dept: desired_dept }).sort({name:1}).pretty();
{ "_id" : 3, "name" : "Jenna", "dept" : 3 }
{ "_id" : 4, "name" : "Steven", "dept" : 3 }
{ "_id" : 2, "name" : "William", "dept" : 3 }def setup() :
port = sys.argv[1]
conn = Connection('localhost', int(port) )
return conn.test
def query_dept_emp(db) :
dept = db.dept
emp = db.emp
for ddoc in dept.find().sort("name",1) :
print "Employees in", ddoc["name"]
for edoc in emp.find( {"dept": ddoc["_id"] } ).sort("name",1) :
print " ", edoc["name"]
def main() :
if len(sys.argv) != 2:
print "usage: ", sys.argv[0], " <port number>"
exit(1)
db = setup()
query_dept_emp(db)
if __name__ == "__main__":
main()Scott