假设我有这个对象:
{
"id": "1a48c847-4fee-4968-8cfd-5f8369c01f64" ,
"sections": [
{
"id": 0 ,
"title": "s1"
} ,
{
"id": 1 ,
"title": "s2"
} ,
{
"id": 2 ,
"title": "s3"
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何直接将第二个标题"s2"更改为其他值?没有加载对象并再次保存?谢谢.
我的数据结构
{
"group": "fruits"
"items": ["apple", "orange", "banana"]
}
Run Code Online (Sandbox Code Playgroud)
我需要在不知道值的情况下从"items"数组中提取第一项.可能吗?
我有一个MeetingService,通过HorizonIO从我的RethinkDB中获取数据.当尝试通过其ID获取会议时,我将始终获得null值作为响应.此服务中的其他方法无问题.
meeting.service.ts:
getMeetingById(passedId: string): Observable<Meeting[]> {
return this.table.find({meetingId: passedId}).fetch();
}
Run Code Online (Sandbox Code Playgroud)
会议-detail.component.ts:
currentMeeting: Meeting;
getCurrentMeeting(): void {
this._meetingsService.getMeetingById(this.passedId).subscribe(
(returnMeetings: Meeting[]) => {
this.currentMeeting = returnMeetings[0];
}
);
}
Run Code Online (Sandbox Code Playgroud)
即使我将passId更改为我直接从我的数据库(通过管理面板)获取的ID,该方法仍然返回null.
如果我更改代码以返回表中的第一个值,一切都会起作用.
getMeetingById(passedId: string): Observable<Meeting[]> {
return this.table.order("meetingId", "descending").limit(1).fetch();
}
Run Code Online (Sandbox Code Playgroud)
最终结果是在我的视图中currentMeeting var上未定义错误:
EXCEPTION: Error in ./MeetingDetailComponent class MeetingDetailComponent - inline template:1:4 caused by:
Cannot read property 'meetingId' of undefined
Run Code Online (Sandbox Code Playgroud)
编辑:显示不同实现的附加代码:
load() {
if(this.passedId != null) {
this._feedService.GetFeedById(this.passedId).subscribe(
(returnFeed: Feed[]) => {
this.currentFeed = returnFeed[0];
}
);
} else {
this._feedService.GetFirstFeed().subscribe(
(returnFeed: Feed[]) => …Run Code Online (Sandbox Code Playgroud) 使用rethinkb和python处理空结果的最佳技巧是什么.我试试这个,但捕捉异常并不令人满意.
@staticmethod
def get_by_mail(mail):
try:
return User(
r.table('users').filter({"mail": mail}).limit(1).nth(0).run()
)
except RqlRuntimeError:
return None
Run Code Online (Sandbox Code Playgroud)
如果有人尝试过其他技术,我很感兴趣.谢谢你的帮助.
如何将MongoDB集合迁移到RethinkDB表?
我并不担心将旧的Mongo _id改为Rethink id,因为在我的实现中它们会被忽略,而我并不担心它们会使我的数据混乱.
我正在参加 Yelp 数据集挑战赛,并使用 RethinkDB 来存储每个不同数据集的 JSON 文档。
我有以下脚本:
import rethinkdb as r
import json, os
RDB_HOST = os.environ.get('RDB_HOST') or 'localhost'
RDB_PORT = os.environ.get('RDB_PORT') or 28015
DB = 'test'
connection = r.connect(host=RDB_HOST, port=RDB_PORT, db=DB)
query = r.table('yelp_user').filter({"name":"Arthur"}).run(connection)
print(query)
Run Code Online (Sandbox Code Playgroud)
但是当我在 virtualenv 的终端上运行它时,我得到以下示例响应:
<rethinkdb.net.DefaultCursor object at 0x102c22250> (streaming):
[{'yelping_since': '2014-03', 'votes': {'cool': 1, 'useful': 2, 'funny': 1}, 'review_count': 5, 'id': '08eb0b0d-2633-4ec4-93fe-817a496d4b52', 'user_id': 'ZuDUSyT4bE6sx-1MzYd2Kg', 'compliments': {}, 'friends': [], 'average_stars': 5, 'type': 'user', 'elite': [], 'name': 'Arthur', 'fans': 0}, ...]
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用 pprint 来漂亮地打印输出,但我不明白如何解决的一个更大问题是以智能方式打印它们,就像不只是将“...”显示为输出的结尾。
有什么建议么?
大多数流行的 NoSQL 数据库(MongoDB、RethinkDB)都不支持 ACID 事务。它们今天在不同系统的开发人员中非常流行。
问题是:没有事务如何保证数据的一致性?我认为数据一致性是生产中的主要事情之一。我错了吗?也许有一些技术可以恢复数据一致性?
我想在我的项目中使用 RethinkDB,但我害怕错过交易。
我正在尝试为 RethinkDB API 制作一个包装模块,但在导入我的类(称为 rethinkdb.py)时遇到了 AttributeError。我在具有共享文件夹“Github”的虚拟机中工作。
我在 IPython 控制台中执行此操作:
import library.api.rethinkdb as re
Run Code Online (Sandbox Code Playgroud)
这是错误:
回溯(最近一次调用最后一次):
文件“”,第 1 行,在 import library.api.rethinkdb as re
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第 51 行,在 conn = Connection().connect_to_database() 中
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第48行,在connect_to_database raise e
AttributeError: 'module' 对象没有属性 'connect'
这是代码:
import rethinkdb as r #The downloaded RethinkDB module from http://rethinkdb.com/
class Connection(object):
def __init__(self, host='127.0.0.1', port=28015, database=None, authentication_key=''):
self.host = host
self.port = port
if database is None:
self.db = 'test'
self.auth_key = authentication_key
def connect_to_database(self):
try:
conn = r.connect(self.host, self.port, self.db, self.auth_key) …Run Code Online (Sandbox Code Playgroud) 我可以在RethinkDB中创建复合主键吗?例如,如果我有一个表与下一个文件结构{authorsId: '371df80c-2efd-48f9-ac37-3edcdb152fb1', postsId: '905e0c92-adcb-4095-98df-fa08ca71b900'},我怎么能在两个authorsId和同时创建主键postsId.或者,如果我不能这样做,我应该如何以三种方式使用多对多的关系.我是使用一个字段作为主键还是第二个作为二级索引?
是否可以执行大量upsert,其行为使得特定字段(例如createdDT:)仅在第一次upsert时设置,而不是在同一记录的后续upsert期间设置?
编辑
有一个原始版本工作,它执行服务器端执行循环,其中每个元素的查找后跟一个条件插入.不是最优雅,也可能是相当可观的性能.还有其他选择吗?
const tableName = "someTableName";
return r.expr(objs).forEach(function (docToInsert) {
return r.table(tableName).get(docToInsert('id')).replace(function (existingDoc) {
return r.branch(
existingDoc.eq(null),
r.expr(docToInsert).merge({ createdDT: r.now() }),
existingDoc.merge(docToInsert)
);
});
});
Run Code Online (Sandbox Code Playgroud)
编辑
标签和标题都不清楚:这个问题与rethinkDB有关
rethinkdb ×10
python ×3
database ×2
angular ×1
connect ×1
horizon ×1
mongodb ×1
nosql ×1
python-3.x ×1
reql ×1
transactions ×1
typescript ×1