スギデータベースSequoiaDBの一般的な操作
4638 ワード
。 nosql , sql 。 sql , :
1. , as , select a._id as id from xx.xx as a, as 。
2. , 。
3.
:db.exec("select a.* from scott.person as a") --a.*
db.exec("select a.name,a.age from scott.person as a,scott.personNameAge as b where a.name=b.name") -- a,b
4. 。
--
root@iZwz91f71l9kck30hh2hkoZ:~# sdb
> db = new Sdb('localhost',11810) --
> db.createCS("scott") --
> db.scott.createCL("person") --
> db.help() --
> db.scott.help()
> db.scott.person.help()
--
> db.scott.person.insert({name:"hadoop",age:10})
> db.scott.person.insert({name:"spark",age:5})
> db.execUpdate("insert into scott.person (name,value) values ('sdb',3)") --sql
--
> db.scott.person.find()
> db.scott.person.find({},{name:1}) --select name from xx.xx
> db.scott.person.find({name:"hadoop"},{name:1}) --select name from xx.xx where name='hadoop'
> db.exec("select * from scott.person") --sql
--
> db.scott.person.update({$set:{age:11}},{name:"hadoop"}) --update xx.xx set age=11 where name='hadoop'
> db.scott.person.update({$unset:{age:""}},{name:"hadoop"}) -- name='hadoop' , drop age
> db.execUpdate("update scott.person set age=11 where name='hadoop'") --sql
--
> db.scott.person.remove({name:"hadoop"}) --delete from table xx.xx where name='hadoop'
> db.scott.person.remove() --delete from table xx.xx
> db.scott.person.truncate() --truncate table xx.xx
> db.dropCL("person") --drop table xx
> db.execUpdate("delete from scott.person where name='hadoop'") --sql
--drop
> db.scott.person.update({$unset:{age:""}}) --alter table scott.person drop column age;
Takes 0.1191s.
--insert...select
db.execUpdate("insert into scott.person select * from scott.personNameAge") -- ,objectid
db.execUpdate("insert into scott.person select id,name from scott.personNameScore") --
--insert(for )
for(var i=0; i<=7; i++) db.scott.rq.insert({rq:i})
for(var i=1; i<=100; i++) db.scott.test.insert({id:i,name:"name"+i,rq:i%7})
--limit n offset m m , n
> db.exec("select bsfwtmc from scott.t_yjd order by _id limit 3 offset 3")
{
"bsfwtmc": " "
}
{
"bsfwtmc": " "
}
{
"bsfwtmc": " "
}
Return 3 row(s).
-- _id
db.scott.t_bsfwt.find({_id:{"$oid":"589bcbf01a7edd1f1b000000"}})
> db.exec("select max(_id) as id from scott.t_bsfwt")
{
"id": {
"$oid": "589bcbf01a7edd1f1b00020d"
}
}
Return 1 row(s).
Takes 0.9621s.
> db.exec("select min(_id) as id from scott.t_bsfwt")
{
"id": {
"$oid": "589bcbf01a7edd1f1b000000"
}
}
--exists null
bar age
> db.foo.bar.find({age:{$exists:1}})
bar content name
> db.foo.bar.find({"content.name":{$exists:0}})
--like , Regex 0 9
db.exec("select gzzkb from scott.t_bsfwt where gzzkb like '^[0-9]' ")
db.scott.t_bsfwt.find({bsfwt_dm:{$regex:'24419.*',$options:'i'}})
> db.scott.person.find({name:Regex("b","i")}) --like '%b%'
> db.scott.person.find({name:Regex("^.bc$","i")}) --like '_bc%'
> db.scott.person.find({name:Regex("^.bb$","i")}) --like '_bb%'
--
import org.bson.BasicBSONObject;
import com.sequoiadb.base.CollectionSpace;
import com.sequoiadb.base.DBCollection;
import com.sequoiadb.base.DBCursor;
import com.sequoiadb.base.Sequoiadb;
public class TestSdb_page{
public static void main(String[] args) {
String connString="iZ94ps2ghdsZ:11810";
String username="";
String password="";
Sequoiadb db = new Sequoiadb(connString, username, password);
CollectionSpace scott = db.getCollectionSpace("scott");
DBCollection cl = scott.getCollection("cl");
//cl.query(matcher, selector, orderBy, hint, skipRows, returnRows)
cl.query("", "", "", "", 0, 20)
}
}