Template parse errors - Angular 5 - ionic-framework

I've read and encountered this issue many times. I am not sure if this is related to Ang 5.I have tried to downgrade to 4. No Luck so far. Any thought.
From what I read, my attempt to resolve the below issue was to add in app.module.ts:
import { CommonModule } from '#angular/common';
import { ErrorHandler, NgModule, NO_ERRORS_SCHEMA,CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
Error in console:
" Property binding ngForIn not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "#NgModule.declarations" .... "
this is my code
home.html
<ion-header>
<ion-navbar>
<ion-title>
{{eventItem.title}}
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<p>{{eventItem.title}}</p>
<p>{{tasktItem.title}} - {{tasktItem.status}}</p>
<p>{{checkListItem.title}}</p>
<ion-list>
<ion-item *ngFor="let item in checkListItem.tasks">
{{item.title}}
</ion-item>
</ion-list>
</ion-content>
home.ts
import { Component } from '#angular/core';
import { CommonModule } from '#angular/common';
import { NavController } from 'ionic-angular';
import { Event, Task, Checklist } from '../../app/shared/event';
import { Item, ItemType, Priority } from '../../app/shared/item';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
string:string
array:any[]
eventItem:Event;
taskItem:Task;
checkListItem:Checklist
constructor(public navCtrl: NavController) {
this.array = []
this.eventItem = new Event(10, "this is a new event", new Date(), ItemType.Event)
this.taskItem = new Task(10, "this is a new task", new Date(), ItemType.Task)
this.checkListItem = new Checklist(12, "this is a new checklist", new Date(), ItemType.Checklist)
for (let i = 1; i <= 10 ; i++) {
let task = new Task(i, `this is task number:${i}`, new Date(), ItemType.Task)
this.array.push(task)
}
this.checkListItem.tasks = this.array
this.eventItem.description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu augue leo. Duis consequat urna quis egestas porttitor. Sed in rhoncus velit. Vivamus euismod vestibulum nisi, eu ornare erat volutpat in. Quisque commodo nisi urna, non porttitor eros porttitor volutpat. Praesent malesuada ultrices enim ut interdum. Ut suscipit sed lorem ac facilisis. Aenean et sapien quis diam hendrerit rhoncus. Praesent ac blandit libero. Duis varius congue lorem sit amet pharetra. Etiam dictum leo eget tincidunt eleifend. Suspendisse volutpat justo augue, vitae pulvinar turpis cursus at."
this.taskItem.description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu augue leo. Duis consequat urna quis egestas porttitor. Sed in rhoncus velit. Vivamus euismod vestibulum nisi, eu ornare erat volutpat in. Quisque commodo nisi urna, non porttitor eros porttitor volutpat. Praesent malesuada ultrices enim ut interdum. Ut suscipit sed lorem ac facilisis. Aenean et sapien quis diam hendrerit rhoncus. Praesent ac blandit libero. Duis varius congue lorem sit amet pharetra. Etiam dictum leo eget tincidunt eleifend. Suspendisse volutpat justo augue, vitae pulvinar turpis cursus at."
}
}
this is my app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { CommonModule } from '#angular/common';
import { ErrorHandler, NgModule, NO_ERRORS_SCHEMA,CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '#ionic-native/splash-screen';
import { StatusBar } from '#ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
#NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
schemas: [NO_ERRORS_SCHEMA,CUSTOM_ELEMENTS_SCHEMA],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
Do you think this is a bug and if it should be fixed anytime soon? I do not remember having a syntax-related error in the past. I cannot really find a workaround. Thanks for the help.

Try this:
<ion-item *ngFor="let item of checkListItem.tasks">
instead of:
<ion-item *ngFor="let item in checkListItem.tasks">
for ... in loops over properties of objects.
for ... of loops over arrays.
From Angular docs: NgForOf

Related

SwiftUI - How to make NavigationView not affect geometry reader's location

I'm trying to get the position of a scrollview using a geometry reader. However, I've noticed that it gives me a different value depending on if I have it embedded in a NavigationView or not. Here is an example:
struct ContentView: View {
#State var headerLocation: CGFloat = 0
var body: some View {
ZStack(alignment: .top) {
Color.white
.ignoresSafeArea()
VStack(spacing: 0) {
ZStack {
Text("test.username")
.font(.custom("Helvetica Bold", size: 18))
}
.frame(height: 40)
.overlay(alignment: .bottom) {
GeometryReader { geo -> Color in
let minY = geo.frame(in: .global).minY
DispatchQueue.main.async {
if headerLocation == 0 {
headerLocation = minY
}
}
return Color.blue
}
.frame(width: 100, height: 1)
}
ScrollView {
VStack(spacing: 8) {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
GeometryReader { proxy -> Color in
let offset = proxy.frame(in: .global).minY
print("\(offset), \(headerLocation)")
return Color.green
}
.frame(width: 40, height: 1)
.padding(.top, 10)
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
}
}
}
}
}
}
The code above functions like intended. When the app is started, it sets the location of the blue rectangle at the top of the screen. If we scroll the scrollview, we can see that the number is equal when we scroll the green rectangle to the same location as the blue one.
Now take the code below:
struct ContentView: View {
#State var headerLocation: CGFloat = 0
var body: some View {
NavigationView {
ZStack(alignment: .top) {
Color.white
.ignoresSafeArea()
VStack(spacing: 0) {
ZStack {
Text("test.username")
.font(.custom("Helvetica Bold", size: 18))
}
.frame(height: 40)
.overlay(alignment: .bottom) {
GeometryReader { geo -> Color in
let minY = geo.frame(in: .global).minY
DispatchQueue.main.async {
if headerLocation == 0 {
headerLocation = minY
}
}
return Color.blue
}
.frame(width: 100, height: 1)
}
ScrollView {
VStack(spacing: 8) {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
GeometryReader { proxy -> Color in
let offset = proxy.frame(in: .global).minY
print("\(offset), \(headerLocation)")
return Color.green
}
.frame(width: 40, height: 1)
.padding(.top, 10)
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut eu sem integer vitae. Pretium aenean pharetra magna ac. Vel pretium lectus quam id leo in vitae. Molestie nunc non blandit massa enim nec dui nunc mattis. Ornare quam viverra orci sagittis eu volutpat odio facilisis. Ultrices neque ornare aenean euismod elementum nisi quis. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit amet volutpat consequat mauris. Dapibus ultrices in iaculis nunc sed augue lacus viverra.")
}
}
}
}
.navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
.navigationBarHidden(true)
}
}
}
When we try to do the same thing, we can see that when the green rectangle is at the same location as the blue one, they have different values. How can I achieve the functionality of the first code block while keeping a NavigationView? I've already tried the different NavigationBarDisplayModes and NavigationTitles
Let me introduce you to .coordinateSpace() where you can pick the view you want to use to compare GeometryReaders. Simply put, as you can see, the NavigationView is messing with the values in the GeometryReaders, so since they both exist in the ZStack, we can easily compare them there. The trick is telling the GeometryReaders what view to use. We do this with .coordinateSpace() placed on the ZStack, and then, instead of using .global() we use .named(). I have abbreviated your Text() to make it shorter and clearer. Here is the code at work:
struct ContentView: View {
#State var headerLocation: CGFloat = 0
var body: some View {
NavigationView {
ZStack(alignment: .top) {
Color.white
.ignoresSafeArea()
VStack(spacing: 0) {
ZStack {
Text("test.username")
.font(.custom("Helvetica Bold", size: 18))
}
.frame(height: 40)
.overlay(alignment: .bottom) {
GeometryReader { geo -> Color in
//Use .named() instead of .global()
let minY = geo.frame(in: .named("ZStack")).minY
DispatchQueue.main.async {
if headerLocation == 0 {
headerLocation = minY
}
}
return Color.blue
}
.frame(width: 100, height: 1)
}
ScrollView {
VStack(spacing: 8) {
Text("Lorem.")
GeometryReader { proxy -> Color in
//Use .named() instead of .global()
let offset = proxy.frame(in: .named("ZStack")).minY
print("\(offset), \(headerLocation)")
return Color.green
}
.frame(width: 40, height: 1)
.padding(.top, 10)
Text("Lorem.")
Text("Lorem.")
Text("Lorem.")
Text("Lorem.")
}
}
}
}
// Put the .coordinateSpace here. The name can be any hashable value.
.coordinateSpace(name: "ZStack")
.navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
.navigationBarHidden(true)
}
}
}

SwiftUI MacOS List layout glitches when changing content order

For ease of reproduction, I have included sample code below to fully recreate my issue.
The Problem
There seems to be a bug that messes up with a lists layout when changing the order of its contents, it only seems to affect MacOS in my testing.
It doesn't occur with ScrollView but in this case Its imperative that I use List (as I need the 'double tap to open window' functionality of navigation link that only seems to work in List)
Any workarounds or solutions would be greatly appreciated. Thanks!
import SwiftUI
struct Book : Hashable {
var title: String
var description: String
}
struct ContentView: View {
#State var books : [Book] = [
Book(title: "Book 1", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ligula urna, vestibulum in consequat facilisis, efficitur quis quam. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent in ullamcorper lectus, eget accumsan nisi. Vivamus lorem ante, auctor in ultricies a, gravida id ligula. Etiam vitae ante augue. "),
Book(title: "Book 2", description: "Ut consectetur ligula massa, in convallis diam consequat eu. Praesent nec justo blandit, posuere nisl a, consequat orci. Fusce maximus laoreet magna, ut commodo neque pellentesque eu. Aliquam condimentum urna massa, eget efficitur orci ultrices ut. Curabitur euismod feugiat mollis. Cras urna elit, varius vel lorem at, convallis tempus sapien. Integer vel purus gravida, tempus quam ac, molestie justo."),
Book(title: "Book 3", description: "Nulla congue mi eget suscipit elementum. Donec efficitur ante id lorem fringilla tempus. Vivamus et interdum nisi.")
]
#State var sortedBooks = [Book]()
func sortBooksByTitle(){
sortedBooks = books.sorted {
$0.title < $1.title
}
}
func sortBooksBytDesc(){
sortedBooks = books.sorted {
$0.description < $1.description
}
}
var body: some View {
VStack{
HStack{
Button(action: {
sortBooksBytDesc()
}, label: {
Text("Sort By description")
})
Button(action: {
sortBooksByTitle()
}, label: {
Text("Sort By title")
})
}
List{
ForEach(sortedBooks, id: \.self) { book in
VStack{
Text(book.title)
.font(.title)
Text(book.description)
.foregroundColor(.gray)
}
}
}
}
.onAppear{
sortBooksByTitle()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Tested on Xcode 12.3 and run on MacOS
Solution:
Add: .id(UUID()) to end of List

Flutter - I want to show only first 2 Paragraphs

So I have a Big passage with like 8 Paragraphs. But I only want to show the first 2 paras.
Let's take the below example:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla scelerisque et urna id porttitor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer vitae auctor diam. Curabitur ipsum turpis, porta sit amet lorem sit amet, ultricies gravida turpis. Mauris congue purus nec tortor laoreet, eu rutrum ligula egestas. Morbi ut magna sapien. Aliquam malesuada velit nec lorem ultricies facilisis. Praesent imperdiet porttitor sodales.
Proin vel arcu purus. Ut nulla lectus, mattis nec condimentum quis, vulputate ac lacus. Suspendisse potenti. Duis consectetur ante ac ultricies sagittis. Donec finibus tortor eu nibh volutpat, non tincidunt nibh malesuada. Nunc sit amet purus vel arcu facilisis facilisis. Pellentesque felis nunc, bibendum fringilla auctor a, varius sit amet nibh.
Maecenas scelerisque, lacus eu gravida fermentum, magna magna finibus urna, eu pulvinar nisl nisi sed velit. Sed in iaculis lacus, sed ornare ipsum. Fusce commodo risus quis arcu volutpat, vitae sollicitudin dolor pellentesque. Phasellus lacus quam, placerat eu lorem vitae, congue accumsan metus. Fusce ultricies vehicula tempus. Aenean a urna tempus, eleifend felis et, venenatis justo. Aliquam quis dapibus risus. Nunc gravida sodales metus, eget aliquet nunc vestibulum vitae. Donec semper finibus ex ac elementum. Maecenas sed nulla id tellus viverra tincidunt quis sed leo. Fusce quis condimentum elit. Donec ultricies imperdiet pulvinar. Nunc egestas quis leo eu cursus. Sed faucibus, enim non dictum commodo, velit felis maximus risus, ut hendrerit dui augue vel justo.
I am getting this data from an API. I only want to show the first 2 paragraphs starting with Lorem ipsum & Proin vel respectively.
I have no idea how to do this. I tried searching the web but did not find any useful information.
var p = text.split('\n\n').take(2);
or if it's needed to join into single string
var p = text.split('\n\n').take(2).join('\n\n');
The Text Widget has the property of max lines you can use it to specify how many lines from a paragraph should be shown. And there is a text-overflow property that can help you get more control over it. Following is an example.
Text(
"This is a long text",
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
),

How can I change the data in an object in MongoDB?

My desired end result is to change the data in an object in MongoDB using Hyper as my terminal. So far, this is the context of what I'm talking about: the DB, the collections, and the objects.
My database...
> show dbs
blogDB 0.000GB
Using my database...
> use blogDB
switched to db blogDB
My collection...
> show collections
posts
My objects...
> db.posts.find()
{ "_id" : ObjectId("5f00acc1324fc732401ad2f2"), "title" : "Day 1", "content" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "__v" : 0 }
{ "_id" : ObjectId("5f013318f1fbfe63547d34a6"), "title" : "Day 2", "content" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "__v" : 0 }
{ "_id" : ObjectId("5f01338c8d56ee5070ccd331"), "title" : "Day 3", "content" : "Mattis nunc sed blandit libero volutpat sed cras. Lectus vestibulum mattis ullamcorper velit. Eget mi proin sed libero enim sed faucibus turpis. Dui accumsan sit amet nulla facilisi morbi tempus. A condimentum vitae sapien pellentesque habitant morbi tristique. Nunc sed id semper risus in hendrerit. Odio pellentesque diam volutpat commodo. Nunc lobortis mattis aliquam faucibus purus. Nec nam aliquam sem et tortor consequat id porta. Pellentesque id nibh tortor id aliquet lectus proin nibh nisl. Urna et pharetra pharetra massa massa ultricies
mi.", "__v" : 0 }
What I've tried to use to achieve my desired end result and what occurred when I attempted it...
> db.posts.updateOne({title: Day 2}, {$set: {content: Sed risus pretium quam vulputate. Nec ullamcorper sit amet risus nullam eget felis. Sit amet mattis vulputate enim nulla aliquet. Nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est. Scelerisque felis imperdiet proin fermentum. Tempus iaculis urna id volutpat lacus laoreet non curabitur gravida. Phasellus faucibus scelerisque eleifend donec. Arcu cursus vitae congue mauris rhoncus. Faucibus scelerisque eleifend donec pretium. Nunc lobortis mattis aliquam faucibus purus in. Vitae auctor eu augue ut lectus. Lectus mauris ultrices eros in cursus turpis massa.}})
2020-07-05T21:04:04.747-0400 E QUERY [js] uncaught exception: SyntaxError: missing } after property list :
#(shell):1:31
> db.posts.updateOne({_id: ObjectId("5f013318f1fbfe63547d34a6")}, {$set: {content: Sed risus pretium quam vulputate. Nec ullamcorper sit amet risus nullam eget felis. Sit amet mattis vulputate enim nulla aliquet. Nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est. Scelerisque felis imperdiet proin fermentum. Tempus iaculis urna id volutpat lacus laoreet non curabitur gravida. Phasellus faucibus scelerisque eleifend donec. Arcu cursus vitae congue mauris rhoncus. Faucibus scelerisque eleifend donec pretium. Nunc lobortis mattis aliquam faucibus purus in. Vitae auctor eu augue ut lectus. Lectus mauris ultrices eros in cursus turpis massa.}})
2020-07-05T21:11:53.463-0400 E QUERY [js] uncaught exception: SyntaxError: missing } after property list :
#(shell):1:85
> db.posts.replaceOne({_id: ObjectId("5f013318f1fbfe63547d34a6")}, {$set: {content: Sed risus pretium quam vulputate. Nec ullamcorper sit amet risus nullam eget felis. Sit amet mattis vulputate enim nulla aliquet. Nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est. Scelerisque felis imperdiet proin fermentum. Tempus iaculis urna id volutpat lacus laoreet non curabitur gravida. Phasellus faucibus scelerisque eleifend donec. Arcu cursus vitae congue mauris rhoncus. Faucibus scelerisque eleifend donec pretium. Nunc lobortis mattis aliquam faucibus purus in. Vitae auctor eu augue ut lectus. Lectus mauris ultrices eros in cursus turpis massa.}})
2020-07-05T21:51:29.498-0400 E QUERY [js] uncaught exception: SyntaxError: missing } after property list :
#(shell):1:86
I also attempted to delete the object so that I could just create a new one in its place. This was the result...
> db.posts.deleteOne({title: Day 2})
2020-07-05T21:08:33.748-0400 E QUERY [js] uncaught exception: SyntaxError: missing } after property list :
#(shell):1:31
Also, to give further clarification (if necessary): this is the database for a website I developed using MongoDB, Mongoose, NodeJS, Javascript, Express and EJS. This website is a simplified blog website which allows a person to compose a new blog post (via a compose page) which is then added to the aforementioned MongoDB.
This website (currently) does not have a 'delete' or 'edit' button/page - something I'm likely to add in the future. For now, any editing or deleting of posts must be done via MongoDB via a terminal (like the Hyper terminal I'm using).
With that said, I greatly appreciate any help. If there's any further clarification or needed information please feel free to ask. I'm still very much a newbie so I'll do my best to answer as clearly as I can muster.
UPDATE:
Following a suggestion from #thammada.ts I added quotes around the data that was a String type which solved my problem and this was the result...
> db.posts.updateOne({_id: ObjectId("5f013318f1fbfe63547d34a6")}, {$set: {content: "Sed risus pretium quam vulputate. Nec ullamcorper sit amet risus nullam eget felis. Sit amet mattis vulputate enim nulla aliquet. Nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est. Scelerisque felis imperdiet proin fermentum. Tempus iaculis urna id volutpat lacus laoreet non curabitur gravida. Phasellus faucibus scelerisque eleifend donec. Arcu cursus vitae congue mauris rhoncus. Faucibus scelerisque eleifend donec pretium. Nunc lobortis mattis aliquam faucibus purus in. Vitae auctor eu augue ut lectus. Lectus mauris ultrices eros in cursus turpis massa."}})
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
According to thammada.ts:
You have to put quotes around values that are strings, such as "Day 2", just like how they are represented when you run db.posts.find()

KRL: Truncating a string

I'm pulling in an RSS feed from a Tumblr blog. Unlike WordPress, which gives a condensed version of the post in the <description> tag, Tumblr dumps the whole post into the feed with no shortened version at all. I'd like my Kynetx app only to output the first, say, 400 characters if the post is longer than that.
I could emit some JavaScript to do it, something like this:
if (post.length > 400) {
post = post.substring(0, 400);
}
Is there a way to do something like that in KRL directly?
Yes! You can use the extract function which will return an array of matches from a Regex.
Extract function documentation
truncated = originalString.extract(re/^.{100}/gi);
Example Appruleset a60x549 {
meta {
name "string-truncate-test"
description <<
string-truncate-test
>>
author "Mike Grace"
logging on
}
rule testingerlyish {
select when pageview ".*"
pre {
originalString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam id purus quis urna aliquam volutpat. Nullam ut velit enim. Cras eu libero felis, vitae adipiscing dolor. Mauris metus nisi, facilisis vitae hendrerit a, posuere in nisi. Integer convallis, odio eu ultrices luctus, arcu ligula ultrices neque, sit amet aliquet lorem diam eget ipsum. Morbi ullamcorper feugiat urna sagittis volutpat. Nullam tincidunt gravida sem, vel suscipit quam cursus egestas. Etiam quis felis leo, id blandit metus. Vestibulum lacinia tortor sit amet mi consectetur non malesuada arcu hendrerit. In placerat mauris nec quam dictum eleifend. Suspendisse consectetur rutrum mauris id vestibulum. Vivamus dignissim imperdiet lorem sit amet eleifend. Etiam nulla est, feugiat non accumsan egestas, luctus in nulla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras orci libero, aliquet id ultricies id, tempor eu eros. Suspendisse ultricies enim quis dui malesuada condimentum. Sed in est velit, ac volutpat velit. Nunc aliquet commodo pellentesque. Curabitur egestas, nibh sed dapibus imperdiet, urna nisi ultricies justo, nec dictum nulla est vitae lectus. Morsapien purus tincidunt nulla, sit amet sodales nisi mi sit amet purus. In facilisis ligula vitae sapien aliquet condimentum. Integer lacus dolor, tincidunt dapibus consequat id, luctus et erat. Praesent vel nunc enim. Donec dignissim dui tincidunt lacus molestie in laoreet ligula placerat. Nullam elit magna, luctus sit amet vestibulum ut, dignissim eget elit. Pellentesque nunc massa, auctor sit amet venenatis sed, hendrerit eu nibh. Vestibulum in nisi purus, eget dictum velit. Phasellus pulvinar odio sed nulla egestas lacinia. Donec porttitor lobortis porta. Nullam imperdiet dapibus pulvinar. Sed ut quam tellus. Sed ornare vulputate facilisis. Suspendisse potenti. Nullam aliquet nulla id enim suscipit iaculis pellentesque lectus vulputate. Cras ullamcorper nunc nec eros porta quis fermentum lectus mattis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas ac imperdiet nisi. Morbi nec elit in eros varius luctus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque aliquet, elit et mattis dignissim, metus tortor fringilla mauris, fermentum bibendum metus mi et lorem. Ut at magna quam, ac condimentum ipsum. Aenean aliquam elementum nisl vitae tempus. Fusce molestie, metus nec egestas facilisis, velit turpis bibendum quam, nec blandit arcu leo non ligula. Morbi nisl neque, gravida in pulvinar ut, sollicitudin eu nunc. Phasellus eget sagittis nunc. Praesent nibh libero, lacinia placerat fermentum a, fringilla sit amet mi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed odio dolor, dignissim a dictum ut, fringilla sit amet purus. Duis et justo et felis tempus pulvinar id eget odio. Suspendisse ac turpis sit amet orci laoreet cursus. Aliquam at odio quis massa pulvinar sollicitudin. Cras nec laoreet metus. Mauris consectetur mauris sit amet nulla rutrum quis tristique erat placerat. Phasellus id felis enim, et molestie dolor. Maecenas dignissim faucibus augue vitae pulvinar. Pellentesque auctor massa eu massa sagittis rutrum. In varius dignissim odio, eu .";
truncated = originalString.extract(re/^.{100}/gi);
}
{
notify("Truncated",truncated[0]) with sticky = true;
}
}
}
Example app run on example.com using bookmarklet: