本文整理汇总了Java中org.jongo.MongoCollection.insert方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCollection.insert方法的具体用法?Java MongoCollection.insert怎么用?Java MongoCollection.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jongo.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Before
public void setUp() {
UserAccount clientAccount = new UserAccount();
clientAccount.setUserName("wh_client");
clientAccount.setPassword("wh_secret");
clientAccount.setAuthorities(new String[] {AUTH_CLIENT});
MongoCollection collection = jongo.getCollection(USER_REPO);
collection.insert(clientAccount);
UserAccount userAccount = new UserAccount();
userAccount.setUserName("test");
userAccount.setPassword("password");
userAccount.setAuthorities(new String[] {AUTH_USER});
userAccount.setCollections(new ArrayList<String>() {{ add("test-collection"); }});
ResponseEntity<Void> responseEntity = restTemplate
.withBasicAuth("wh_client", "wh_secret")
.postForEntity("/api/v1/user/create", userAccount, Void.class);
assertNotNull(responseEntity);
assertEquals(responseEntity.getStatusCodeValue(), 200);
}
示例2: saveImage
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Saves an image in the database.
*
* @param name The filename of the image, including type.
* @param file The file to be saved.
* @param path The special path that ties an event to an image.
* @param type The mimetype of the image.
* @return A boolean that indicates whether the saving was successful.
*/
@Override
public boolean saveImage(String name, MultipartFile file, String path, String type) {
byte[] imageByteArray;
try {
imageByteArray = file.getBytes();
} catch (IOException e) {
e.printStackTrace();
return false;
}
Image image = new Image(name, imageByteArray, path, type);
MongoCollection collection = client.getClient().getCollection("images");
collection.insert(image);
return true;
}
示例3: createUser
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public UserEntity createUser(String accountId, String username) {
JongoDBService manager = AppContext.getManager(JongoDBService.class);
Jongo jongo = manager.getJongo();
MongoCollection collection = jongo.getCollection("USER");
UserEntity userEntity = new UserEntity();
userEntity.setUserId(accountId);
userEntity.setAccountId(accountId);
userEntity.setLevel(1);
userEntity.setUserName(username);
try {
collection.insert(userEntity);
return userEntity;
} catch (com.mongodb.DuplicateKeyException e) {
}
return null;
}
示例4: writeModuleVersion
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void writeModuleVersion(String moduleName, long version) throws TypeStorageException {
try {
MongoCollection vers = jdb.getCollection(TABLE_MODULE_VERSION);
if (vers.findOne("{moduleName:#}", moduleName).as(ModuleVersion.class) == null) {
ModuleVersion ver = new ModuleVersion();
ver.setModuleName(moduleName);
ver.setVersionTime(version);
ver.setReleasedVersionTime(version);
ver.setSupported(true);
vers.insert(ver);
} else {
vers.update("{moduleName:#}", moduleName).with("{$set: {versionTime: #}}", version);
}
} catch (Exception e) {
throw new TypeStorageException(e);
}
}
示例5: writeModuleRecords
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Override
public void writeModuleRecords(ModuleInfo info, String specDocument, long version)
throws TypeStorageException {
writeModuleVersion(info.getModuleName(), version);
writeModuleInfo(info, version);
try {
MongoCollection specs = jdb.getCollection(TABLE_MODULE_SPEC_HISTORY);
ModuleSpec spec = new ModuleSpec();
spec.setModuleName(info.getModuleName());
spec.setDocument(specDocument);
spec.setVersionTime(version);
specs.insert(spec);
} catch (Exception e) {
throw new TypeStorageException(e);
}
}
示例6: writeTypeSchemaRecord
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Override
public void writeTypeSchemaRecord(String moduleName, String typeName,
String version, long moduleVersion, String document, String md5) throws TypeStorageException {
try {
MongoCollection recs = jdb.getCollection(TABLE_MODULE_TYPE_SCHEMA);
recs.remove("{moduleName:#,typeName:#,version:#}", moduleName, typeName, version);
TypeRecord rec = new TypeRecord();
rec.setModuleName(moduleName);
rec.setTypeName(typeName);
rec.setVersion(version);
rec.setModuleVersion(moduleVersion);
rec.setDocument(document);
rec.setMd5hash(md5);
recs.insert(rec);
} catch (Exception e) {
throw new TypeStorageException(e);
}
}
示例7: prepareClientAuth
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void prepareClientAuth() {
UserAccount clientAccount = new UserAccount();
clientAccount.setUserName(clientId);
clientAccount.setPassword(clientSecret);
clientAccount.setAuthorities(new String[]{AUTH_CLIENT});
MongoCollection collection = jongo.getCollection(USER_REPO);
collection.insert(clientAccount);
}
示例8: setUp
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Before
public void setUp() {
UserAccount clientAccount = new UserAccount();
clientAccount.setUserName("wh_client");
clientAccount.setPassword("wh_secret");
clientAccount.setAuthorities(new String[] {AUTH_CLIENT});
MongoCollection collection = jongo.getCollection(USER_REPO);
collection.insert(clientAccount);
}
示例9: createEvent
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Stores a created event in the database.
*
* @param event An Event object.
* @return The created event.
*/
public Event createEvent(Event event) {
MongoCollection collection = db.getClient().getCollection("events");
collection.ensureIndex("{ location.coordinates: '2dsphere' }");
collection.insert(event);
return event;
}
示例10: regeditAccount
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public AccountEntity regeditAccount(String account,String password){
JongoDBService manager = AppContext.getManager(JongoDBService.class);
Jongo jongo = manager.getJongo();
AccountEntity accountEntity=new AccountEntity();
accountEntity.setAccountName(account);
accountEntity.setAccountPassWord(password);
MongoCollection collection = jongo.getCollection("Account");
try {
collection.insert(accountEntity);
return accountEntity;
} catch (com.mongodb.DuplicateKeyException e) {
}
return null;
}
示例11: main
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public static void main(String[] args) {
DB db = new MongoClient("192.168.0.199",32770).getDB("fly");
Jongo jongo = new Jongo(db);
AccountEntity accountEntity=new AccountEntity();
accountEntity.setAccountName("test2");
accountEntity.setAccountPassWord("1234");
MongoCollection collection = jongo.getCollection("Account");
try {
collection.insert(accountEntity);
} catch (com.mongodb.DuplicateKeyException e) {
System.out.println("1245");
}
AccountEntity as = collection.findOne("{_id:#,accountPassWord:#}","test2","12345").as(AccountEntity.class);
System.out.println(as);
}
示例12: createUser
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public boolean createUser(Jongo jongo ,UserEntity userEntity){
MongoCollection collection = jongo.getCollection("UserEntity");
try {
WriteResult insert = collection.insert(userEntity);
Object upsertedId = insert.getUpsertedId();
return true;
} catch (com.mongodb.DuplicateKeyException e) {
return false;
}
}
示例13: createPlaneEntity
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public PlaneEntity createPlaneEntity(Jongo jongo ,String accountId,String userId){
PlaneEntity entity=new PlaneEntity();
MongoCollection collection = jongo.getCollection("PlaneEntity");
try {
collection.insert(entity);
return entity;
} catch (com.mongodb.DuplicateKeyException e) {
return null;
}
}
示例14: regeditAccount
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public AccountEntity regeditAccount(Jongo jongo ,String account,String password){
AccountEntity accountEntity=new AccountEntity();
accountEntity.setAccountId(account);
accountEntity.setPassword(password);
MongoCollection collection = jongo.getCollection("AccountEntity");
try {
collection.insert(accountEntity);
return accountEntity;
} catch (com.mongodb.DuplicateKeyException e) {
return null;
}
}
示例15: main
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
// or, to connect to a replica set, with auto-discovery of the primary, supply a seed list of members
MongoClient mongoClient = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017),
new ServerAddress("localhost", 27018),
new ServerAddress("localhost", 27019)));
// MongoClient mongo = new MongoClient();
DB db = mongoClient.getDB("yourdb");
Jongo jongo = new Jongo(db);
MongoCollection jens = jongo.getCollection("jens");
jens.insert(new Cat("jens's Cat"));
mongoClient.close();
}