有人可以帮我解决如何在Cloud Firestore中重命名,移动或更新文档或集合名称的问题吗?
无论如何,我还可以访问我的Cloud Firestore来更新终端或任何应用程序中的集合或文档吗?
在Firestore 文档中有更新嵌套对象字段的代码,但没有关于如何在嵌套对象中添加新字段的代码或文档?
// Assume the document contains:
// {
// name: "Frank",
// favorites: { food: "Pizza", color: "Blue", subject: "recess" }
// age: 12
// }
//
// To update age and favorite color:
db.collection("users").document("frank")
.update(
"age", 13,
"favorites.color", "Red"
);
Run Code Online (Sandbox Code Playgroud)
正如您在这里看到的,我们正在更新favorites.colorto Red,但是我们如何code在favorites对象中添加新字段?
假设我想更新上述文档如下:
{
name: "Frank",
favorites: { food: "Pizza", color: "Blue", subject: "recess", code:32 }
age: 12
}
Run Code Online (Sandbox Code Playgroud) 我在我的 Android 应用程序中使用 Cloud Firestore 数据库,并且我在集合中有不同的文档,例如:用户 uid、餐厅的按键和我的食谱的数字。
我的数据库:
users
uid1
uid2
...
resturants
pushedId1
pushedId2
...
recipes
0001
0002
...
Run Code Online (Sandbox Code Playgroud)
对于我了解使用 uid 的用户,但最好为我的餐厅使用 Firestore 推送的 id?这是约定还是为什么要使用它?
我还尝试使用UUID 类生成唯一键但对我来说只使用数字作为我的食谱更容易。这是一个糟糕的方法吗?
任何帮助将不胜感激,谢谢!
{
"breviario": {
"metaLiturgia": {
"fecha" : "Martes 5 de febrero del 2019",
"tiempo" : "PROPIO DE LOS SANTOS",
"semana" : "",
"mensaje": "",
"salterio": "",
"color":0,
"meta": ""
},
"santo": {
"nombre": "Santa Águeda, virgen y mártir",
"vida": "Padeció el martirio en Catania (Sicilia), probablemente en la persecución de Decio. Desde la antigüedad su culto se extendió por toda la Iglesia y su nombre fue introducido en el Canon romano."
},
"oficio": {
"himno": {
"texto": "Testigos de …Run Code Online (Sandbox Code Playgroud) 我有一个简单的google authentification应用程序,我想显示一条欢迎消息.如果电子邮件帐户为j ohnsmith@gmail.com,我想Toast用"欢迎约翰·史密斯!" 我怎样才能做到这一点?
这是我的代码:
if (user == null) {
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE);
} else {
Toast.makeText(MainActivity.this, "Welcome " + userName, Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我试图使用此代码,但我只获取用户名,而不是名字和姓氏.
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有两个活动,我正在分别从这两个活动向Firestore添加数据.但是,每当我向Firestore添加第二个活动数据时,它都会覆盖第一个活动数据.我在以下两个活动中使用了以下代码:
firebaseFirestore.collection("Users").document(user_id).set(data)
Run Code Online (Sandbox Code Playgroud)
如何停止覆盖?我想将两个活动数据保存在同一个中user_id.
java android firebase firebase-realtime-database google-cloud-firestore
我想减少阅读次数,以便从
QuestionCollection(Array of Questions) 中获取问题的详细信息。
我的应用程序就像是 stackoverflow 的一部分。
我想显示一个问题有多少赞、浏览量和评论。所以为了处理这个我创建了多个集合
问题集
评论集
问题点赞
问题视图
问题标签
我认为CommentCollection (comments) 只属于一个问题。所以我正在考虑QuestionCollection像数组或集合一样合并(但它需要另一个读取命中)。哪个更好?
我想totalViews,totalLikes在 QuestionCollection中添加两个变量的( )。但是每次我都必须检查这个问题是否被这个用户喜欢或被这个用户查看。
给我一个建议或替代方案,这样我就可以尽可能少地获取问题详细信息。
编辑
为了显示视图计数, 我迭代并计算QuestionViews 集合,其中 questionID == myQuestionID
为了显示喜欢计数, 我迭代并计算QuestionLikes 集合,其中 questionID == myQuestionID
为什么我不将它添加到 QuestionCollection?因为我想展示最多查看和最喜欢的问题,例如 stackoverflow。如果我将它添加到 QuestionCollection 我怎么知道最喜欢和最多查看的问题。
我想从uploadTask.addOnProgressListenerFirebase 的方法中获取下载网址。如何使用以下代码获取下载网址?
UploadTask uploadTask = storageRef.putBytes(data);
uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
{
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
{
Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
}
});
Run Code Online (Sandbox Code Playgroud)
我用过,taskSnapshot.getTask().getResult()但这不起作用。
嗨,我正在使用 Android Studio,但在转换从 Firestore 获得的数据时遇到了麻烦。我将数据保存在 Firestore 类型 GeoPoint 中,我想查询它并转换为 Object 类型LatLng。
这是我的代码:
final FirebaseFirestore db = FirebaseFirestore.getInstance();
final CollectionReference stores = db.collection("stores");
stores.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.i(TAG,document.getData().get("position").toString());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我得到的
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=29.339555, longitude=169.715858 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=68.085393, longitude=-42.081575 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint …Run Code Online (Sandbox Code Playgroud) 我在使用RecycleViewFirebase中的数据创建片段时遇到问题.我希望应用程序显示RecycleView我点击按钮后从一个片段更改为RecycleView片段,但它确实更改了显示的片段,但它没有显示任何内容.
我知道有很多这样的问题,但我似乎没有找到解决这个问题的正确方法.
我已经完成了Firebase RecyclerView所需的一切,并且还尝试在一个活动而不是片段中构建它,它确实有效,但不是片段.我试图在onCreateView方法,onActivityCreated和onViewCreated方法中初始化适配器和recyclerview,但它们似乎都没有工作.
这是我的片段代码:
private KidAdapter adapter;
private RecyclerView recyclerView;
Button button;
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.uangsaku_menu_fragment, container, false);
button = view.findViewById(R.id.btn_add);
button.setOnClickListener(this);
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
setUpRecyclerView();
return view;
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.btn_add){
Intent intent = new Intent(getActivity(), Register.class);
startActivity(intent);
}
}
public void setUpRecyclerView(){
Query query = FirebaseDatabase.getInstance().getReference("kids");
FirebaseRecyclerOptions<kidData> options = new FirebaseRecyclerOptions.Builder<kidData>()
.setQuery(query, kidData.class) …Run Code Online (Sandbox Code Playgroud)