这个js,依照官网写的
var ioc = {
zMongo : {
args : [ "mg","mg123","127.0.0.1",9099,"mg" ],
factory : "org.nutz.mongo.ZMongo#me"
},
zMoDB : {
args : [ "mg" ], // 数据库名称
factory : "$zMongo#db"
}
}
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mongo.ZMoDB;
import org.nutz.mongo.ZMongo;
import com.alibaba.fastjson.JSONObject;
@IocBean
public class MongodbService {
@Inject
protected ZMongo zmongo; //注意大小写与配置的名字一致
@Inject
protected ZMoDB zMoDB; // 当前数据
public void insert() {
JSONObject j = new JSONObject();
j.put("a", "1111");
zMoDB.getNativeDB().getCollection("tomcat").insert(ZMo.me().toDocArray(j));;
}
}